]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
realloc(NULL, ...) is equivalent to malloc(...)
authorAlejandro Colomar <alx@kernel.org>
Sat, 27 May 2023 13:35:13 +0000 (15:35 +0200)
committerSerge Hallyn <serge@hallyn.com>
Thu, 8 Jun 2023 14:05:39 +0000 (09:05 -0500)
Don't have a branch for when the old pointer is NULL.  realloc(3) can
handle that case just fine.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/subordinateio.c

index 49356e23aa7ddb860bbb18ef779465a92abba278..52d0e33d1ee705ab64526133efa7edeaee3e2e93 100644 (file)
@@ -315,17 +315,13 @@ static bool have_range(struct commonio_db *db,
 
 static bool append_range(struct subid_range **ranges, const struct subordinate_range *new, int n)
 {
-       if (!*ranges) {
-               *ranges = MALLOC(1, struct subid_range);
-               if (!*ranges)
-                       return false;
-       } else {
-               struct subid_range *alloced;
-               alloced = REALLOC(*ranges, n + 1, struct subid_range);
-               if (!alloced)
-                       return false;
-               *ranges = alloced;
-       }
+       struct subid_range  *alloced;
+
+       alloced = REALLOC(*ranges, n + 1, struct subid_range);
+       if (!alloced)
+               return false;
+       *ranges = alloced;
+
        (*ranges)[n].start = new->start;
        (*ranges)[n].count = new->count;
        return true;