diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2005-08-06 18:38:35 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2005-08-06 18:38:35 +0000 |
commit | f701ca518d2da8b85c73e98a21044e7444c4abf9 (patch) | |
tree | 445b7cc383338201ef49d09308a0158e7a79ce31 /util.c | |
parent | 7969d74ddb2023f4ece01a6208f752999e09672d (diff) |
"setup_tmpdir()" either returns the const string passed to it, or it
returns a malloced string that's supposed to persist as long as Ethereal
is running. Make it return "const char *", and return either the former
pointer or the result of mallocation, so we don't end up using the same
variable for a const pointer and a non-const pointer.
Make the variables to which its result is assigned const pointers as
well.
"strlen()" returns size_t; make a argument to which its result is
assigned a size_t.
Just out of paranoia, check for a zero-length string passed to
"setup_tmpdir()".
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@15247 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -111,22 +111,22 @@ get_args_as_string(int argc, char **argv, int optind) return argstring; } -static char * +static const char * setup_tmpdir(const char *dir) { - int len = strlen(dir); + size_t len = strlen(dir); char *newdir; /* Append path separator if necessary */ - if (dir[len - 1] == G_DIR_SEPARATOR) { - newdir = dir; + if (len != 0 && dir[len - 1] == G_DIR_SEPARATOR) { + return dir; } else { newdir = g_malloc(len + 2); strcpy(newdir, dir); strcat(newdir, G_DIR_SEPARATOR_S); + return newdir; } - return newdir; } static int @@ -161,11 +161,11 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx) return tmp_fd; } -static char *tmpdir = NULL; +static const char *tmpdir = NULL; #ifdef _WIN32 static char *temp = NULL; #endif -static char *E_tmpdir; +static const char *E_tmpdir; #ifndef P_tmpdir #define P_tmpdir "/var/tmp" |