* libc/argz/argz_add_sep.c (argz_add_sep): Handle empty string
argument. * libc/argz/argz_append.c (argz_append): Handle empty buf argument. * libc/argz/argz_create_sep.c (argz_create_sep): Return (NULL, 0) on empty input strings. * libc/argz/argz_extract.c (argz_extract): Check argz_len before looping through argz. * libc/argz/argz_stringify.c (argz_stringify): Ditto.
This commit is contained in:
parent
d74d6b17cd
commit
76a2ee78b6
|
@ -1,3 +1,14 @@
|
|||
2007-05-29 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* libc/argz/argz_add_sep.c (argz_add_sep): Handle empty string
|
||||
argument.
|
||||
* libc/argz/argz_append.c (argz_append): Handle empty buf argument.
|
||||
* libc/argz/argz_create_sep.c (argz_create_sep): Return (NULL, 0)
|
||||
on empty input strings.
|
||||
* libc/argz/argz_extract.c (argz_extract): Check argz_len before
|
||||
looping through argz.
|
||||
* libc/argz/argz_stringify.c (argz_stringify): Ditto.
|
||||
|
||||
2007-05-27 Brian Dessent <brian@dessent.net>
|
||||
|
||||
* libc/stdio/vfprintf.c (_VFPRINTF_R): Populate 'ox' when
|
||||
|
|
|
@ -23,11 +23,14 @@ _DEFUN (argz_add_sep, (argz, argz_len, str, sep),
|
|||
|
||||
argz_create_sep (str, sep, &str_argz, &str_argz_len);
|
||||
|
||||
*argz_len += str_argz_len;
|
||||
if (str_argz_len)
|
||||
{
|
||||
*argz_len += str_argz_len;
|
||||
|
||||
if(!(*argz = (char *)realloc(*argz, *argz_len)))
|
||||
return ENOMEM;
|
||||
if(!(*argz = (char *)realloc(*argz, *argz_len)))
|
||||
return ENOMEM;
|
||||
|
||||
memcpy(*argz + last, str_argz, str_argz_len);
|
||||
memcpy(*argz + last, str_argz, str_argz_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,13 +16,16 @@ _DEFUN (argz_append, (argz, argz_len, buf, buf_len),
|
|||
const char *buf _AND
|
||||
size_t buf_len)
|
||||
{
|
||||
size_t last = *argz_len;
|
||||
if (buf_len)
|
||||
{
|
||||
size_t last = *argz_len;
|
||||
|
||||
*argz_len += buf_len;
|
||||
*argz_len += buf_len;
|
||||
|
||||
if(!(*argz = (char *)realloc(*argz, *argz_len)))
|
||||
return ENOMEM;
|
||||
if(!(*argz = (char *)realloc(*argz, *argz_len)))
|
||||
return ENOMEM;
|
||||
|
||||
memcpy(*argz + last, buf, buf_len);
|
||||
memcpy(*argz + last, buf, buf_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,13 +25,20 @@ _DEFUN (argz_create_sep, (string, sep, argz, argz_len),
|
|||
char *token = 0;
|
||||
char *iter = 0;
|
||||
|
||||
*argz_len = 0;
|
||||
|
||||
if (!string || string[0] == '\0')
|
||||
{
|
||||
*argz= NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
delim[0] = sep;
|
||||
delim[1] = '\0';
|
||||
|
||||
running = strdup(string);
|
||||
old_running = running;
|
||||
|
||||
*argz_len = 0;
|
||||
while ((token = strsep(&running, delim)))
|
||||
{
|
||||
len = strlen(token);
|
||||
|
|
|
@ -17,14 +17,15 @@ _DEFUN (argz_extract, (argz, argz_len, argv),
|
|||
int j = 0;
|
||||
const size_t count = argz_count(argz, argz_len);
|
||||
|
||||
for (i = argz_len - 2; i > 0; i--)
|
||||
{
|
||||
if (argz[i] == '\0')
|
||||
{
|
||||
j++;
|
||||
argv[count - j] = &argz[i + 1];
|
||||
}
|
||||
}
|
||||
if (argz_len > 1)
|
||||
for (i = argz_len - 2; i > 0; i--)
|
||||
{
|
||||
if (argz[i] == '\0')
|
||||
{
|
||||
j++;
|
||||
argv[count - j] = &argz[i + 1];
|
||||
}
|
||||
}
|
||||
argv[0] = &argz[0];
|
||||
argv[count] = NULL;
|
||||
}
|
||||
|
|
|
@ -16,9 +16,10 @@ _DEFUN (argz_stringify, (argz, argz_len, sep),
|
|||
size_t i;
|
||||
|
||||
/* len includes trailing \0, which we don't want to replace. */
|
||||
for (i = 0; i < argz_len - 1; i++)
|
||||
{
|
||||
if (argz[i] == '\0')
|
||||
argz[i] = sep;
|
||||
}
|
||||
if (argz_len > 1)
|
||||
for (i = 0; i < argz_len - 1; i++)
|
||||
{
|
||||
if (argz[i] == '\0')
|
||||
argz[i] = sep;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue