changeset 49488:da6abcaef15c

gtkutil.c: Check for NULL string before calling strcmp or strlen.
author Jan Djärv <jan.h.d@swipnet.se>
date Mon, 27 Jan 2003 19:36:10 +0000
parents 6ddd3d2c7a74
children e0ff22ddc744
files src/ChangeLog src/gtkutil.c
diffstat 2 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Jan 27 11:38:45 2003 +0000
+++ b/src/ChangeLog	Mon Jan 27 19:36:10 2003 +0000
@@ -1,3 +1,9 @@
+2003-01-27  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
+
+	* gtkutil.c (create_dialog, xg_separator_p)
+	(xg_item_label_same_p, xg_update_menu_item): Check for NULL string
+	before calling strcmp or strlen.
+
 2003-01-26  Jan D.  <jan.h.d@swipnet.se>
 
 	* gtkutil.c (update_frame_tool_bar): Call prepare_image_for_display
--- a/src/gtkutil.c	Mon Jan 27 11:38:45 2003 +0000
+++ b/src/gtkutil.c	Mon Jan 27 19:36:10 2003 +0000
@@ -759,7 +759,7 @@
       GtkWidget *w;
       GtkRequisition req;
 
-      if (strcmp (item->name, "message") == 0)
+      if (item->name && strcmp (item->name, "message") == 0)
         {
           /* This is the text part of the dialog.  */
           w = gtk_label_new (utf8_label);
@@ -776,7 +776,7 @@
           gtk_widget_size_request (w, &req);
           gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (wdialog)->vbox),
                                req.height);
-	  if (strlen (item->value) > 0)
+	  if (item->value && strlen (item->value) > 0)
             button_spacing = 2*req.width/strlen (item->value);
         }
       else
@@ -1201,8 +1201,10 @@
 static int
 xg_separator_p (char *name)
 {
+  if (! name) return 0;
+
   return strcmp (name, "--") == 0
-    || strcmp (name, "--:") == 0
+    || strncmp (name, "--:", 3) == 0
     || strcmp (name, "---") == 0;
 }
 
@@ -1539,6 +1541,7 @@
   return w;
 }
 
+/* Return the label for menu item WITEM.  */
 static const char *
 xg_get_menu_item_label (witem)
      GtkMenuItem *witem;
@@ -1547,16 +1550,22 @@
   return gtk_label_get_label (wlabel);
 }
 
+/* Return non-zero if the menu item WITEM has the text LABEL.  */
 static int
 xg_item_label_same_p (witem, label)
      GtkMenuItem *witem;
      char *label;
 {
-  int is_same;
+  int is_same = 0;
   char *utf8_label = get_utf8_string (label);
-  
-  is_same = strcmp (utf8_label, xg_get_menu_item_label (witem)) == 0;
-  if (utf8_label != label) g_free (utf8_label);
+  const char *old_label = witem ? xg_get_menu_item_label (witem) : 0;
+
+  if (! old_label && ! utf8_label)
+    is_same = 1;
+  else if (old_label && utf8_label)
+    is_same = strcmp (utf8_label, old_label) == 0;
+
+  if (utf8_label && utf8_label != label) g_free (utf8_label);
 
   return is_same;
 }
@@ -1773,6 +1782,8 @@
   GtkLabel *wkey = 0;
   char *utf8_label;
   char *utf8_key;
+  const char *old_label = 0;
+  const char *old_key = 0;
   xg_menu_item_cb_data *cb_data;
   
   wchild = gtk_bin_get_child (GTK_BIN (w));  
@@ -1812,14 +1823,18 @@
         }
     }
 
-  if (utf8_key && strcmp (utf8_key, gtk_label_get_label (wkey)) != 0)
+  
+  if (wkey) old_key = gtk_label_get_label (wkey);
+  if (wlbl) old_label = gtk_label_get_label (wlbl);
+  
+  if (wkey && utf8_key && (! old_key || strcmp (utf8_key, old_key) != 0))
     gtk_label_set_text (wkey, utf8_key);
 
-  if (strcmp (utf8_label, gtk_label_get_label (wlbl)) != 0)
+  if (! old_label || strcmp (utf8_label, old_label) != 0)
     gtk_label_set_text_with_mnemonic (wlbl, utf8_label);
 
-  if (utf8_key != val->key) g_free (utf8_key);
-  if (utf8_label != val->name) g_free (utf8_label);
+  if (utf8_key && utf8_key != val->key) g_free (utf8_key);
+  if (utf8_label && utf8_label != val->name) g_free (utf8_label);
   
   if (! val->enabled && GTK_WIDGET_SENSITIVE (w))
     gtk_widget_set_sensitive (w, FALSE);