Skip to content

Commit 2ed8eca

Browse files
committed
Merge branch 'rj/commit-slab-fix'
* rj/commit-slab-fix: commit-slab.h: Fix memory allocation and addressing
2 parents af77c0b + d7a1d62 commit 2ed8eca

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

commit-slab.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void init_ ##slabname## _with_stride(struct slabname *s, \
4848
if (!stride) \
4949
stride = 1; \
5050
s->stride = stride; \
51-
elem_size = sizeof(struct slabname) * stride; \
51+
elem_size = sizeof(elemtype) * stride; \
5252
s->slab_size = COMMIT_SLAB_SIZE / elem_size; \
5353
s->slab_count = 0; \
5454
s->slab = NULL; \
@@ -72,11 +72,10 @@ static void clear_ ##slabname(struct slabname *s) \
7272
static elemtype *slabname## _at(struct slabname *s, \
7373
const struct commit *c) \
7474
{ \
75-
int nth_slab, nth_slot, ix; \
75+
int nth_slab, nth_slot; \
7676
\
77-
ix = c->index * s->stride; \
78-
nth_slab = ix / s->slab_size; \
79-
nth_slot = ix % s->slab_size; \
77+
nth_slab = c->index / s->slab_size; \
78+
nth_slot = c->index % s->slab_size; \
8079
\
8180
if (s->slab_count <= nth_slab) { \
8281
int i; \
@@ -89,8 +88,8 @@ static elemtype *slabname## _at(struct slabname *s, \
8988
} \
9089
if (!s->slab[nth_slab]) \
9190
s->slab[nth_slab] = xcalloc(s->slab_size, \
92-
sizeof(**s->slab)); \
93-
return &s->slab[nth_slab][nth_slot]; \
91+
sizeof(**s->slab) * s->stride); \
92+
return &s->slab[nth_slab][nth_slot * s->stride]; \
9493
} \
9594
\
9695
static int stat_ ##slabname## realloc

0 commit comments

Comments
 (0)