2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 06:15:37 +00:00

It's safe to rely on C89 semantics for realloc(NULL, size).

This commit is contained in:
Todd C. Miller
2015-06-20 19:27:31 -06:00
parent 887a76489a
commit d7224ea502
2 changed files with 4 additions and 5 deletions

View File

@@ -45,7 +45,7 @@ sudo_getline(char **bufp, size_t *bufsizep, FILE *fp)
bufsize = *bufp ? *bufsizep : 0;
if (bufsize == 0 || bufsize - 1 < len) {
bufsize = len + 1;
cp = *bufp ? realloc(*bufp, bufsize) : malloc(bufsize);
cp = realloc(*bufp, bufsize);
if (cp == NULL)
return -1;
*bufp = cp;
@@ -68,7 +68,7 @@ sudo_getline(char **bufp, size_t *bufsizep, FILE *fp)
bufsize = *bufsizep;
if (buf == NULL || bufsize == 0) {
bufsize = LINE_MAX;
cp = buf ? realloc(buf, bufsize) : malloc(bufsize);
cp = realloc(buf, bufsize);
if (cp == NULL)
return -1;
buf = cp;

View File

@@ -142,10 +142,9 @@ fill_args(const char *s, int len, int addspace)
if (new_len >= arg_size) {
/* Allocate more space than we need for subsequent args */
while (new_len >= (arg_size += COMMANDARGINC))
;
continue;
p = sudoerslval.command.args ?
realloc(sudoerslval.command.args, arg_size) : malloc(arg_size);
p = realloc(sudoerslval.command.args, arg_size);
if (p == NULL) {
free(sudoerslval.command.args);
sudo_warn(NULL);