diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-07-31 12:38:27 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-07-31 12:38:27 -0700 |
commit | 2ed8ecaf57271e506cefffb5f777f50a6a91a4b4 (patch) | |
tree | c52250446aecceaf2492a49ac29517998d3246a6 | |
parent | af77c0b1cf3f8c8ba5ae30cec208227800447f99 (diff) | |
parent | d7a1d629c3be95f8c2ddd1973b9dae9dd893048f (diff) | |
download | git-2ed8ecaf57271e506cefffb5f777f50a6a91a4b4.tar.gz |
Merge branch 'rj/commit-slab-fix'
* rj/commit-slab-fix:
commit-slab.h: Fix memory allocation and addressing
-rw-r--r-- | commit-slab.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/commit-slab.h b/commit-slab.h index 7d481638af..d4c8286470 100644 --- a/commit-slab.h +++ b/commit-slab.h @@ -48,7 +48,7 @@ static void init_ ##slabname## _with_stride(struct slabname *s, \ if (!stride) \ stride = 1; \ s->stride = stride; \ - elem_size = sizeof(struct slabname) * stride; \ + elem_size = sizeof(elemtype) * stride; \ s->slab_size = COMMIT_SLAB_SIZE / elem_size; \ s->slab_count = 0; \ s->slab = NULL; \ @@ -72,11 +72,10 @@ static void clear_ ##slabname(struct slabname *s) \ static elemtype *slabname## _at(struct slabname *s, \ const struct commit *c) \ { \ - int nth_slab, nth_slot, ix; \ + int nth_slab, nth_slot; \ \ - ix = c->index * s->stride; \ - nth_slab = ix / s->slab_size; \ - nth_slot = ix % s->slab_size; \ + nth_slab = c->index / s->slab_size; \ + nth_slot = c->index % s->slab_size; \ \ if (s->slab_count <= nth_slab) { \ int i; \ @@ -89,8 +88,8 @@ static elemtype *slabname## _at(struct slabname *s, \ } \ if (!s->slab[nth_slab]) \ s->slab[nth_slab] = xcalloc(s->slab_size, \ - sizeof(**s->slab)); \ - return &s->slab[nth_slab][nth_slot]; \ + sizeof(**s->slab) * s->stride); \ + return &s->slab[nth_slab][nth_slot * s->stride]; \ } \ \ static int stat_ ##slabname## realloc |