]> granicus.if.org Git - sudo/commitdiff
It's safe to rely on C89 semantics for realloc(NULL, size).
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 21 Jun 2015 01:27:31 +0000 (19:27 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 21 Jun 2015 01:27:31 +0000 (19:27 -0600)
lib/util/getline.c
plugins/sudoers/toke_util.c

index 60bc6f918d0d835b758185ba1ae3d1868f0888f7..23c5cce4c18b513c676c9e09502865ef3ad3bb0b 100644 (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;
index 67d07143132b547c4babca2f62e6dc45dd6372f6..52a0d7673ca13c504cbd99393a7fde968a43a3fb 100644 (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);