[gnome-games] utils: Make CueSheet.get_track() throw error



commit 04e6afa45e3010f49c8f4bcefc769b06706389a9
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Jul 29 16:20:49 2016 +0200

    utils: Make CueSheet.get_track() throw error
    
    Make the get_track() method of CueSheet throw an error when trying to
    access a non existing track.
    
    This avoids segmentation errors.
    
    Fixes #322

 src/utils/cue-sheet/cue-sheet-error.vala |    1 +
 src/utils/cue-sheet/cue-sheet.vala       |    5 ++++-
 2 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/src/utils/cue-sheet/cue-sheet-error.vala b/src/utils/cue-sheet/cue-sheet-error.vala
index c950e72..2a5a47f 100644
--- a/src/utils/cue-sheet/cue-sheet-error.vala
+++ b/src/utils/cue-sheet/cue-sheet-error.vala
@@ -7,4 +7,5 @@ private errordomain Games.CueSheetError {
        INVALID_FILE_FORMAT,
        INVALID_TRACK_NUMBER,
        INVALID_TRACK_MODE,
+       NOT_A_TRACK,
 }
diff --git a/src/utils/cue-sheet/cue-sheet.vala b/src/utils/cue-sheet/cue-sheet.vala
index 5b42d06..3a0f5a6 100644
--- a/src/utils/cue-sheet/cue-sheet.vala
+++ b/src/utils/cue-sheet/cue-sheet.vala
@@ -20,7 +20,10 @@ public class Games.CueSheet : Object {
                parse ();
        }
 
-       public CueSheetTrackNode get_track (size_t i) {
+       public CueSheetTrackNode get_track (uint i) throws Error {
+               if (i >= tracks.length)
+                       throw new CueSheetError.NOT_A_TRACK (_("'%s' doesn't have a track for index %u."), 
file.get_uri (), i);
+
                return tracks[i];
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]