On Fri, 17 Sep 2010, Tamas TEVESZ wrote:

 > i meant the following, but it's not perfect. it correctly notifies 
 > about which item is deemed to be bad, but (after having the warning 
 > dismissed) clicking on "save" causes wprefs to segfault. i suspect 
 > this is because the corresponding proplist node isn't actually 
 > cleared, and it causes trouble later on. pulling this part off is 
 > probably going to be a bit tricky.

or maybe not, for both items.

i am starting to think that there are a complete pallets of canned 
worms are waiting patiently.

it looks to me that fixing this particular segfault bento caught 
actually just paves the way for several more -- functions that chew on 
proplist types can, at times, receive null values, but they don't 
quite handle this situation.

the following is a touchup of bento's original work and that of i saw 
later when trying to save. there is still one issue remaining, namely 
that even after having claimed the bad item was cleared, it still 
shows up on the editable menu popup, but it will not be present in the 
saved menu or anywhere, as far as i can tell.

i think this can sorta go in, credit is fully bento's.

but don't let this stop anyone from tracking down the remaining issue 
;)

diff --git a/WPrefs.app/Menu.c b/WPrefs.app/Menu.c
index dccb85b..5c2713a 100644
--- a/WPrefs.app/Menu.c
+++ b/WPrefs.app/Menu.c
@@ -509,7 +509,7 @@ static void createPanel(_Panel * p)
                data->param.exec.command = "eterm";
 
                data = putNewItem(panel, pad, ExecInfo, _("Run..."));
-               data->param.exec.command = _("%a(Run,Type command to run)");
+               data->param.exec.command = _("%A(Run,Type command to run)");
 
                data = putNewItem(panel, pad, ExecInfo, _("Netscape"));
                data->param.exec.command = "netscape";
@@ -1030,7 +1030,8 @@ static ItemData *parseCommand(WMPropList * item)
                        cmd = 11;
                } else {
                        wwarning(_("unknown command '%s' in menu"), command);
-                       goto error;
+                       wfree(data);
+                       return NULL;
                }
 
                data->type = CommandInfo;
@@ -1043,11 +1044,6 @@ static ItemData *parseCommand(WMPropList * item)
        }
 
        return data;
-
- error:
-       wfree(data);
-
-       return NULL;
 }
 
 static void updateFrameTitle(_Panel * panel, char *title, InfoType type)
@@ -1400,9 +1396,18 @@ static WEditMenu *buildSubmenu(_Panel * panel, 
WMPropList * pl)
 
                        data = parseCommand(pi);
 
-                       if (panel->markerPix[data->type])
-                               WSetEditMenuItemImage(item, 
panel->markerPix[data->type]);
-                       WSetEditMenuItemData(item, data, (WMCallback *) 
freeItemData);
+                       if(data != NULL) {
+                               if (panel->markerPix[data->type])
+                                       WSetEditMenuItemImage(item, 
panel->markerPix[data->type]);
+                               WSetEditMenuItemData(item, data, (WMCallback *) 
freeItemData);
+                       } else {
+                               char *buf = wmalloc(1024);
+                               snprintf(buf, 1024, _("Invalid menu command 
\"%s\" with label \"%s\" cleared"),
+                                       WMGetFromPLString(WMGetFromPLArray(pi, 
1)),
+                                       WMGetFromPLString(WMGetFromPLArray(pi, 
0)));
+                               WMRunAlertPanel(scr, panel->parent, 
_("Warning"), buf, _("OK"), NULL, NULL);
+                               wfree(buf);
+                       }
                }
        }
 
@@ -1509,6 +1514,9 @@ static WMPropList *processData(char *title, ItemData * 
data)
        static WMPropList *pomenu = NULL;
        int i;
 
+       if(data == NULL)
+               return NULL;
+
        if (!pscut) {
                pscut = WMCreatePLString("SHORTCUT");
                pomenu = WMCreatePLString("OPEN_MENU");
@@ -1638,7 +1646,7 @@ static WMPropList *processSubmenu(WEditMenu * menu)
        pmenu = WMCreatePLArray(pl, NULL);
 
        i = 0;
-       while ((item = WGetEditMenuItem(menu, i++))) {
+       while (item = WGetEditMenuItem(menu, i++)) {
                WEditMenu *submenu;
 
                s = WGetEditMenuItemTitle(item);

-- 
[-]

mkdir /nonexistent
diff --git a/WPrefs.app/Menu.c b/WPrefs.app/Menu.c
index dccb85b..5c2713a 100644
--- a/WPrefs.app/Menu.c
+++ b/WPrefs.app/Menu.c
@@ -509,7 +509,7 @@ static void createPanel(_Panel * p)
 		data->param.exec.command = "eterm";
 
 		data = putNewItem(panel, pad, ExecInfo, _("Run..."));
-		data->param.exec.command = _("%a(Run,Type command to run)");
+		data->param.exec.command = _("%A(Run,Type command to run)");
 
 		data = putNewItem(panel, pad, ExecInfo, _("Netscape"));
 		data->param.exec.command = "netscape";
@@ -1030,7 +1030,8 @@ static ItemData *parseCommand(WMPropList * item)
 			cmd = 11;
 		} else {
 			wwarning(_("unknown command '%s' in menu"), command);
-			goto error;
+			wfree(data);
+			return NULL;
 		}
 
 		data->type = CommandInfo;
@@ -1043,11 +1044,6 @@ static ItemData *parseCommand(WMPropList * item)
 	}
 
 	return data;
-
- error:
-	wfree(data);
-
-	return NULL;
 }
 
 static void updateFrameTitle(_Panel * panel, char *title, InfoType type)
@@ -1400,9 +1396,18 @@ static WEditMenu *buildSubmenu(_Panel * panel, WMPropList * pl)
 
 			data = parseCommand(pi);
 
-			if (panel->markerPix[data->type])
-				WSetEditMenuItemImage(item, panel->markerPix[data->type]);
-			WSetEditMenuItemData(item, data, (WMCallback *) freeItemData);
+			if(data != NULL) {
+				if (panel->markerPix[data->type])
+					WSetEditMenuItemImage(item, panel->markerPix[data->type]);
+				WSetEditMenuItemData(item, data, (WMCallback *) freeItemData);
+			} else {
+				char *buf = wmalloc(1024);
+				snprintf(buf, 1024, _("Invalid menu command \"%s\" with label \"%s\" cleared"),
+					WMGetFromPLString(WMGetFromPLArray(pi, 1)),
+					WMGetFromPLString(WMGetFromPLArray(pi, 0)));
+				WMRunAlertPanel(scr, panel->parent, _("Warning"), buf, _("OK"), NULL, NULL);
+				wfree(buf);
+			}
 		}
 	}
 
@@ -1509,6 +1514,9 @@ static WMPropList *processData(char *title, ItemData * data)
 	static WMPropList *pomenu = NULL;
 	int i;
 
+	if(data == NULL)
+		return NULL;
+
 	if (!pscut) {
 		pscut = WMCreatePLString("SHORTCUT");
 		pomenu = WMCreatePLString("OPEN_MENU");
@@ -1638,7 +1646,7 @@ static WMPropList *processSubmenu(WEditMenu * menu)
 	pmenu = WMCreatePLArray(pl, NULL);
 
 	i = 0;
-	while ((item = WGetEditMenuItem(menu, i++))) {
+	while (item = WGetEditMenuItem(menu, i++)) {
 		WEditMenu *submenu;
 
 		s = WGetEditMenuItemTitle(item);

Reply via email to