Ted Unangst wrote:
> I think using sizeof(*dbv) would be the better idiom.

Here's an updated diff, including Tobias Stoeckmann's fix.


Index: src/usr.bin/locate/locate/util.c
===================================================================
RCS file: /cvs/src/usr.bin/locate/locate/util.c,v
retrieving revision 1.11
diff -u -p -u -r1.11 util.c
--- src/usr.bin/locate/locate/util.c    8 Oct 2014 04:04:37 -0000       1.11
+++ src/usr.bin/locate/locate/util.c    15 Nov 2014 20:51:09 -0000
@@ -72,8 +72,8 @@ check_bigram_char(ch)
 
 /* split a colon separated string into a char vector
  *
- * "bla:foo" -> {"foo", "bla"}
- * "bla:"    -> {"foo", dot}
+ * "bla:foo" -> {"bla", "foo"}
+ * "bla:"    -> {"bla", dot}
  * "bla"     -> {"bla"}
  * ""       -> do nothing
  *
@@ -89,7 +89,7 @@ colon(dbv, path, dot)
        char **pv;
 
        if (dbv == NULL) {
-               if ((dbv = malloc(sizeof(char **))) == NULL)
+               if ((dbv = malloc(sizeof(*dbv))) == NULL)
                        err(1, "malloc");
                *dbv = NULL;
        }
@@ -123,7 +123,7 @@ colon(dbv, path, dot)
                        }
                        /* increase dbv with element p */
                        if ((newdbv = reallocarray(dbv, vlen + 2,
-                           sizeof(char **))) == NULL)
+                           sizeof(*newdbv))) == NULL)
                                err(1, "realloc");
                        dbv = newdbv;
                        *(dbv + vlen) = p;

Reply via email to