From b8788e9c0d944a225ca56f1e45b50e583c5a4a28 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 20 Nov 2002 04:54:01 +0000 Subject: [PATCH] Should really fix #98303 2002-11-19 Havoc Pennington Should really fix #98303 * src/prefs.c (meta_prefs_change_workspace_name): add bad hack to treat empty string the same as null * src/menu.c (get_workspace_name_with_accel): allocate one more than the length of "name" so we have room for a nul byte (and don't malloc(0) on empty strings). Also some formatting cleanups. --- ChangeLog | 11 +++++++++++ src/menu.c | 15 ++++++++------- src/prefs.c | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d7c3e8b3..509e04d7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-11-19 Havoc Pennington + + Should really fix #98303 + + * src/prefs.c (meta_prefs_change_workspace_name): add + bad hack to treat empty string the same as null + + * src/menu.c (get_workspace_name_with_accel): allocate one more + than the length of "name" so we have room for a nul byte (and + don't malloc(0) on empty strings). Also some formatting cleanups. + 2002-11-19 Havoc Pennington * src/window.c (meta_window_client_message): do a diff --git a/src/menu.c b/src/menu.c index ea340b9ea..335e965ba 100644 --- a/src/menu.c +++ b/src/menu.c @@ -131,7 +131,7 @@ activate_cb (GtkWidget *menuitem, gpointer data) * The calling code owns the string, and is reponsible to free the * memory after use. */ -static char * +static char* get_workspace_name_with_accel (Display *display, Window xroot, int index) @@ -148,6 +148,7 @@ get_workspace_name_with_accel (Display *display, * integer, insert a '_' before the number if it is less than 10 and * return it */ + number = 0; if (sscanf (name, _("Workspace %d"), &number) == 1) { char *new_name; @@ -171,24 +172,24 @@ get_workspace_name_with_accel (Display *display, char *new_name; const char *source; char *dest; - source = name; + /* * Assume the worst case, that every character is a _ */ - dest = new_name = g_malloc0 (strlen (name) * 2); + new_name = g_malloc0 (strlen (name) * 2 + 1); + /* * Now iterate down the strings, adding '_' to escape as we go */ + dest = new_name; + source = name; while (*source != '\0') { if (*source == '_') *dest++ = '_'; *dest++ = *source++; } - /* - * We don't free *name as we don't own it, and pass ownership of - * *new_name to the calling code. - */ + return new_name; } } diff --git a/src/prefs.c b/src/prefs.c index 3b55ca3ae..502506e03 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -1602,6 +1602,10 @@ meta_prefs_get_workspace_name (int i) g_return_val_if_fail (i >= 0 && i < MAX_REASONABLE_WORKSPACES, NULL); g_assert (workspace_names[i] != NULL); + + meta_topic (META_DEBUG_PREFS, + "Getting workspace name for %d: \"%s\"\n", + i, workspace_names[i]); return workspace_names[i]; } @@ -1615,6 +1619,19 @@ meta_prefs_change_workspace_name (int i, g_return_if_fail (i >= 0 && i < MAX_REASONABLE_WORKSPACES); + meta_topic (META_DEBUG_PREFS, + "Changing name of workspace %d to %s\n", + i, name ? name : "none"); + + /* This is a bad hack. We have to treat empty string as + * "unset" because the root window property can't contain + * null. So it gets empty string instead and we don't want + * that to result in setting the empty string as a value that + * overrides "unset". + */ + if (name && *name == '\0') + name = NULL; + if ((name == NULL && workspace_names[i] == NULL) || (name && workspace_names[i] && strcmp (name, workspace_names[i]) == 0)) {