Use reallocarray() to replace the one remaining realloc() in find.

 - todd

Index: usr.bin/find/misc.c
===================================================================
RCS file: /cvs/src/usr.bin/find/misc.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 misc.c
--- usr.bin/find/misc.c 14 Jul 2015 16:16:07 -0000      1.13
+++ usr.bin/find/misc.c 14 Jul 2015 16:21:18 -0000
@@ -60,14 +60,14 @@ brace_subst(char *orig, char **store, ch
        for (p = *store; (ch = *orig); ++orig)
                if (ch == '{' && orig[1] == '}') {
                        while ((p - *store) + plen > len) {
-                               int newlen = len * 2;
                                char *newstore;
 
-                               if (!(newstore = realloc(*store, newlen)))
+                               newstore = reallocarray(*store, len, 2);
+                               if (newstore == NULL)
                                        err(1, NULL);
                                p = (p - *store) + newstore;
                                *store = newstore;
-                               len = newlen;
+                               len *= 2;
                        }
                        memmove(p, path, plen);
                        p += plen;

Reply via email to