[sound-juicer/gnome-3-18] genres: Fix crasher with empty genres file



commit 7bf3ad2ed5fea275653a9c3014bd740d10f4e255
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Nov 21 17:26:22 2015 +0100

    genres: Fix crasher with empty genres file
    
    If g_strv_length() is 0, we'd then try to access the strv at index -1
    which is obviously not a good thing to do.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758451

 src/sj-genres.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/src/sj-genres.c b/src/sj-genres.c
index b2392e8..5a4f477 100644
--- a/src/sj-genres.c
+++ b/src/sj-genres.c
@@ -84,9 +84,11 @@ static char** saved_genres (void) {
   if (success) {
     genres_from_file = g_strsplit (file_contents, "\n", 0);
     len = g_strv_length (genres_from_file);
-    if (strlen (genres_from_file[len-1]) == 0) {
-      g_free (genres_from_file[len-1]);
-      genres_from_file[len-1] = NULL;
+    if (len >= 1) {
+      if (strlen (genres_from_file[len-1]) == 0) {
+        g_free (genres_from_file[len-1]);
+        genres_from_file[len-1] = NULL;
+      }
     }
 
     g_free (file_contents);


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