From: Thomas Rast Date: Sun, 1 Dec 2013 20:41:55 +0000 (+0100) Subject: commit-slab: sizeof() the right type in xrealloc X-Git-Tag: v1.9-rc0~74^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cde0a0576c8950599ef11184bc35aea648f7e717 commit-slab: sizeof() the right type in xrealloc 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 Signed-off-by: Thomas Rast Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/commit-slab.h b/commit-slab.h index d068e2d531..cc114b53b0 100644 --- a/commit-slab.h +++ b/commit-slab.h @@ -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; \