fix: prevent crash
authorPhilippe Coval <philippe.coval@open.eurogiciel.org>
Mon, 11 Aug 2014 12:56:21 +0000 (14:56 +0200)
committerManuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Mon, 11 Aug 2014 12:56:21 +0000 (14:56 +0200)
when started as:
wlmessage  -titlebuttons Min

Change-Id: I75c9d9cf0953205a5b61f8aae7baa77341f0c5a6
Signed-off-by: Manuel Bachmann <manuel.bachmann@open.eurogiciel.org>
Author:    Philippe Coval <philippe.coval@open.eurogiciel.org>

libwlmessage.c

index ca828c8..7ee564e 100644 (file)
@@ -71,10 +71,11 @@ get_number_of_lines (char *text)
 
        gchar **lines = g_strsplit (text, "\n", -1);
 
-       while ((lines[lines_num] != NULL) && (lines_num < MAX_LINES))
-               lines_num++;
-
-       g_strfreev (lines);
+       if (lines) {
+               while ((lines[lines_num] != NULL) && (lines_num < MAX_LINES))
+                       lines_num++;
+               g_strfreev (lines);
+       }
 
        return lines_num;
 }
@@ -87,14 +88,15 @@ get_max_length_of_lines (char *text)
 
        gchar **lines = g_strsplit (text, "\n", -1);
 
-       while ((lines[lines_num] != NULL) && (lines_num < MAX_LINES)) {
-               if (strlen (lines[lines_num]) > length)
-                       length = strlen (lines[lines_num]);
-               lines_num++;
+       if (lines) {
+               while ((lines[lines_num] != NULL) && (lines_num < MAX_LINES)) {
+                       if (strlen (lines[lines_num]) > length)
+                               length = strlen (lines[lines_num]);
+                       lines_num++;
+               }
+               g_strfreev (lines);
        }
 
-       g_strfreev (lines);
-
        return length;
 }