"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
This commit is contained in:
Guy Harris 2005-08-06 18:38:35 +00:00
parent e108e80811
commit d473807893
1 changed files with 7 additions and 7 deletions

14
util.c
View File

@ -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"