commit-slab: sizeof() the right type in xrealloc
authorThomas Rast <tr@thomasrast.ch>
Sun, 1 Dec 2013 20:41:55 +0000 (21:41 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Dec 2013 20:46:01 +0000 (12:46 -0800)
When allocating the slab, the code accidentally computed the array
size from s->slab (an elemtype**). The slab is an array of elemtype*,
however, so we should take the size of *s->slab.

Noticed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Thomas Rast <tr@thomasrast.ch>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-slab.h
index d068e2d5316c93cd5120d56cfd146a34b9fe2913..cc114b53b096c6fc8574629b86659a639fdfed61 100644 (file)
@@ -91,7 +91,7 @@ static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s,      \
        if (s->slab_count <= nth_slab) {                                \
                int i;                                                  \
                s->slab = xrealloc(s->slab,                             \
-                                  (nth_slab + 1) * sizeof(s->slab));   \
+                                  (nth_slab + 1) * sizeof(*s->slab));  \
                stat_ ##slabname## realloc++;                           \
                for (i = s->slab_count; i <= nth_slab; i++)             \
                        s->slab[i] = NULL;                              \