From 9f6a39e83fd79ca005bdf2298568bff8cd8de8e0 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Sat, 25 Sep 2004 14:34:27 +0000 Subject: [PATCH] * command.c (examine_cd): Likewise. Additionally used g_strdup to not accidentally modify an environment variable. * complete.c (command_completion_function): Likewise. (filename_completion_function): Likewise. (try_complete): Likewise. (variable_completion_function): Likewise. --- src/ChangeLog | 5 +++++ src/command.c | 7 +++++-- src/complete.c | 36 ++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 948c53c80..6e3c61746 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -5,6 +5,11 @@ * view.c (hex_search): Added const qualifier. * boxes.c (display_unit): Likewise. + * command.c (examine_cd): Likewise. Additionally used g_strdup to + not accidentally modify an environment variable. + * complete.c (command_completion_function): Likewise. + (filename_completion_function): Likewise. (try_complete): Likewise. + (variable_completion_function): Likewise. * file.c (check_hardlinks): Likewise. * find.c (find_do_view_edit): Likewise. (find_file): Likewise. * global.h (home_dir): Likewise. diff --git a/src/command.c b/src/command.c index 3f4405a14..fe2245bc9 100644 --- a/src/command.c +++ b/src/command.c @@ -57,7 +57,8 @@ examine_cd (char *path) { int result, qlen; char *path_tilde; - char *p, *q, *r, *s, *t, c; + char *p, *q, *r, *s, c; + const char *t; /* Tilde expansion */ path_tilde = tilde_expand (path); @@ -107,7 +108,8 @@ examine_cd (char *path) /* CDPATH handling */ if (*q != PATH_SEP && !result) { - p = getenv ("CDPATH"); + char * const cdpath = g_strdup (getenv ("CDPATH")); + char *p = cdpath; if (p == NULL) c = 0; else @@ -126,6 +128,7 @@ examine_cd (char *path) *s = c; p = s + 1; } + g_free (cdpath); } g_free (q); g_free (path_tilde); diff --git a/src/complete.c b/src/complete.c index ce8da2c7c..738abd9bf 100644 --- a/src/complete.c +++ b/src/complete.c @@ -64,7 +64,7 @@ filename_completion_function (char *text, int state) /* If we're starting the match process, initialize us a bit. */ if (!state){ - char *temp; + const char *temp; g_free (dirname); g_free (filename); @@ -229,7 +229,7 @@ variable_completion_function (char *text, int state) { static char **env_p; static int varlen, isbrace; - char *p = 0; + const char *p = NULL; if (!state){ /* Initialization stuff */ isbrace = (text [1] == '{'); @@ -396,7 +396,7 @@ hostname_completion_function (char *text, int state) static char * command_completion_function (char *text, int state) { - static char *path_end; + static const char *path_end; static int isabsolute; static int phase; static int text_len; @@ -418,7 +418,7 @@ command_completion_function (char *text, int state) "shift", "source", "suspend", "test", "times", "trap", "type", "typeset", "ulimit", "umask", "unalias", "unset", "wait", 0 }; - char *p, *found; + char *found; if (!state) { /* Initialize us a little bit */ isabsolute = strchr (text, PATH_SEP) != 0; @@ -427,10 +427,10 @@ command_completion_function (char *text, int state) words = bash_reserved; phase = 0; text_len = strlen (text); - if (!path && (path = getenv ("PATH")) != NULL) { - p = path = g_strdup (path); + if (!path && (path = g_strdup (getenv ("PATH"))) != NULL) { + char *p = path; path_end = strchr (p, 0); - while ((p = strchr (p, PATH_ENV_SEP))) { + while ((p = (char *) strchr (p, PATH_ENV_SEP))) { *p++ = 0; } } @@ -438,7 +438,7 @@ command_completion_function (char *text, int state) } if (isabsolute) { - p = filename_completion_function (text, state); + char *p = filename_completion_function (text, state); if (!p) look_for_executables = 0; return p; @@ -476,7 +476,7 @@ command_completion_function (char *text, int state) cur_word = concat_dir_and_file (expanded, text); g_free (expanded); canonicalize_pathname (cur_word); - cur_path = strchr (cur_path, 0) + 1; + cur_path = (char *) strchr (cur_path, 0) + 1; init_state = state; } found = @@ -495,12 +495,14 @@ command_completion_function (char *text, int state) path = NULL; return NULL; } - if ((p = strrchr (found, PATH_SEP)) != NULL) { + { char *p; + if ((p = (char *) strrchr (found, PATH_SEP)) != NULL) { p++; p = g_strdup (p); g_free (found); return p; } + } return found; } @@ -665,11 +667,11 @@ try_complete (char *text, int *start, int *end, int flags) } if (flags & INPUT_COMPLETE_COMMANDS) - p = strrchr (word, '`'); + p = (char *) strrchr (word, '`'); if (flags & (INPUT_COMPLETE_COMMANDS | INPUT_COMPLETE_VARIABLES)) - q = strrchr (word, '$'); + q = (char *) strrchr (word, '$'); if (flags & INPUT_COMPLETE_HOSTNAMES) - r = strrchr (word, '@'); + r = (char *) strrchr (word, '@'); if (q && q [1] == '(' && INPUT_COMPLETE_COMMANDS){ if (q > p) p = q + 1; @@ -722,7 +724,8 @@ try_complete (char *text, int *start, int *end, int flags) if (!strncmp (p, "cd", 2)) for (p += 2; *p && p < q && (*p == ' ' || *p == '\t'); p++); if (p == q){ - char *cdpath = getenv ("CDPATH"); + char * const cdpath_ref = g_strdup (getenv ("CDPATH")); + char *cdpath = cdpath_ref; char c, *s, *r; if (cdpath == NULL) @@ -730,9 +733,9 @@ try_complete (char *text, int *start, int *end, int flags) else c = ':'; while (!matches && c == ':'){ - s = strchr (cdpath, ':'); + s = (char *) strchr (cdpath, ':'); if (s == NULL) - s = strchr (cdpath, 0); + s = (char *) strchr (cdpath, 0); c = *s; *s = 0; if (*cdpath){ @@ -745,6 +748,7 @@ try_complete (char *text, int *start, int *end, int flags) *s = c; cdpath = s + 1; } + g_free (cdpath_ref); } } }