diff options
Diffstat (limited to '')
-rw-r--r-- | src/usermenu.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/src/usermenu.c b/src/usermenu.c index c328871..accd9f2 100644 --- a/src/usermenu.c +++ b/src/usermenu.c @@ -1,7 +1,7 @@ /* User Menu implementation - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -86,20 +86,24 @@ static char *menu = NULL; static char * strip_ext (char *ss) { - char *s = ss; + char *s; char *e = NULL; - while (*s != '\0') + if (ss == NULL) + return NULL; + + for (s = ss; *s != '\0'; s++) { if (*s == '.') e = s; if (IS_PATH_SEP (*s) && e != NULL) e = NULL; /* '.' in *directory* name */ - s++; } + if (e != NULL) *e = '\0'; - return ss; + + return (*ss == '\0' ? NULL : ss); } /* --------------------------------------------------------------------------------------------- */ @@ -501,8 +505,11 @@ execute_menu_command (const Widget * edit_widget, const char *commands, gboolean char *tmp; tmp = name_quote (parameter, FALSE); - fputs (tmp, cmd_file); - g_free (tmp); + if (tmp != NULL) + { + fputs (tmp, cmd_file); + g_free (tmp); + } } else fputs (parameter, cmd_file); @@ -528,8 +535,11 @@ execute_menu_command (const Widget * edit_widget, const char *commands, gboolean char *text; text = expand_format (edit_widget, *commands, do_quote); - fputs (text, cmd_file); - g_free (text); + if (text != NULL) + { + fputs (text, cmd_file); + g_free (text); + } } } else if (*commands == '%') @@ -779,7 +789,7 @@ expand_format (const Widget * edit_widget, char c, gboolean do_quote) else { if (get_other_type () != view_listing) - return g_strdup (""); + return NULL; panel = other_panel; } @@ -800,7 +810,7 @@ expand_format (const Widget * edit_widget, char c, gboolean do_quote) default: /* other modes don't use formats */ - return g_strdup (""); + return NULL; } if (do_quote) @@ -822,16 +832,13 @@ expand_format (const Widget * edit_widget, char c, gboolean do_quote) case 'd': { const char *cwd; - char *qstr; if (panel != NULL) cwd = vfs_path_as_str (panel->cwd_vpath); else cwd = vfs_get_current_dir (); - qstr = quote_func (cwd, FALSE); - - result = qstr; + result = quote_func (cwd, FALSE); goto ret; } case 'c': @@ -914,31 +921,37 @@ expand_format (const Widget * edit_widget, char c, gboolean do_quote) case 't': case 'u': { - GString *block; + GString *block = NULL; int i; if (panel == NULL) { - result = g_strdup (""); + result = NULL; goto ret; } - block = g_string_sized_new (16); - for (i = 0; i < panel->dir.len; i++) if (panel->dir.list[i].f.marked != 0) { char *tmp; tmp = quote_func (panel->dir.list[i].fname->str, FALSE); - g_string_append (block, tmp); - g_string_append_c (block, ' '); - g_free (tmp); + if (tmp != NULL) + { + if (block == NULL) + block = g_string_new_take (tmp); + else + { + g_string_append (block, tmp); + g_free (tmp); + } + g_string_append_c (block, ' '); + } if (c_lc == 'u') do_file_mark (panel, i, 0); } - result = g_string_free (block, FALSE); + result = block == NULL ? NULL : g_string_free (block, block->len == 0); goto ret; } /* sub case block */ default: |