git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pack-bitmap: do not core dump
@ 2014-04-22 22:53 Kyle J. McKay
  2014-04-22 23:11 ` Junio C Hamano
  2014-04-22 23:17 ` Jeff King
  0 siblings, 2 replies; 4+ messages in thread
From: Kyle J. McKay @ 2014-04-22 22:53 UTC (permalink / raw)
  To: Junio C Hamano, Jeff King; +Cc: git

So I was trying to use pack.writebitmaps=true and all I got was core dumps.

The fix with a real subject line ;) is below.  I think perhaps this should be
picked up for the 2.0.0 release.  (Patch is against master.)

--Kyle

---- >8 ----
Subject: [PATCH] ewah_bitmap.c: do not assume size_t and eword_t are the same size

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>
---
 ewah/ewah_bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c
index 9ced2dad..fccb42b5 100644
--- a/ewah/ewah_bitmap.c
+++ b/ewah/ewah_bitmap.c
@@ -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)
-- 
1.8.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-23  0:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-22 22:53 [PATCH] pack-bitmap: do not core dump Kyle J. McKay
2014-04-22 23:11 ` Junio C Hamano
2014-04-22 23:17 ` Jeff King
2014-04-23  0:40   ` Kyle J. McKay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).