ewah_bitmap.c: do not assume size_t and eword_t are the same size
authorKyle J. McKay <mackyle@gmail.com>
Tue, 22 Apr 2014 22:53:02 +0000 (15:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Apr 2014 23:21:16 +0000 (16:21 -0700)
When buffer_grow changes the size of the buffer using realloc,
it first computes and saves the rlw pointer's offset into the
buffer using (uint8_t *) math before the realloc but then
restores it using (eword_t *) math.

In order to do this it's necessary to convert the (uint8_t *)
offset into an (eword_t *) offset. It was doing this by
dividing by the sizeof(size_t). Unfortunately sizeof(size_t)
is not same as sizeof(eword_t) on all platforms.

This causes illegal memory accesses and other bad things to
happen when attempting to use bitmaps on those platforms.

Fix this by dividing by the sizeof(eword_t) instead which
will always be correct for all platforms.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ewah/ewah_bitmap.c
index 9ced2dadfe92c2a3cf89ab34a09af85af11de581..fccb42b52cbcbbfd2b5ec9f7f535f2e82a327090 100644 (file)
@@ -41,7 +41,7 @@ static inline void buffer_grow(struct ewah_bitmap *self, size_t new_size)
        self->alloc_size = new_size;
        self->buffer = ewah_realloc(self->buffer,
                self->alloc_size * sizeof(eword_t));
-       self->rlw = self->buffer + (rlw_offset / sizeof(size_t));
+       self->rlw = self->buffer + (rlw_offset / sizeof(eword_t));
 }
 
 static inline void buffer_push(struct ewah_bitmap *self, eword_t value)