aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-08-06 18:38:35 +0000
committerGuy Harris <guy@alum.mit.edu>2005-08-06 18:38:35 +0000
commitd473807893c2a25b9b26ba04b78d2e96d8ed04e2 (patch)
tree445b7cc383338201ef49d09308a0158e7a79ce31 /util.c
parente108e80811bf581a34911a6a96f35fc79433874d (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()". svn path=/trunk/; revision=15247
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/util.c b/util.c
index 63050a54c7..6eb8297a32 100644
--- a/util.c
+++ b/util.c
@@ -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"