mirror of
https://github.com/mirror/wget.git
synced 2025-01-20 17:20:20 +08:00
* src/utils.c (make_directory): Replace alloca by fixed array / xmalloc
This commit is contained in:
parent
4dd9dee2e7
commit
9adde1e441
14
src/utils.c
14
src/utils.c
@ -956,11 +956,19 @@ int
|
||||
make_directory (const char *directory)
|
||||
{
|
||||
int i, ret, quit = 0;
|
||||
char buf[1024];
|
||||
char *dir;
|
||||
size_t len = strlen (directory);
|
||||
|
||||
/* Make a copy of dir, to be able to write to it. Otherwise, the
|
||||
function is unsafe if called with a read-only char *argument. */
|
||||
STRDUP_ALLOCA (dir, directory);
|
||||
if (len < sizeof(buf))
|
||||
{
|
||||
memcpy(buf, directory, len + 1);
|
||||
dir = buf;
|
||||
}
|
||||
else
|
||||
dir = xstrdup(directory);
|
||||
|
||||
/* If the first character of dir is '/', skip it (and thus enable
|
||||
creation of absolute-pathname directories. */
|
||||
@ -983,6 +991,10 @@ make_directory (const char *directory)
|
||||
else
|
||||
dir[i] = '/';
|
||||
}
|
||||
|
||||
if (dir != buf)
|
||||
xfree (dir);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user