git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix git-pack-objects for 64-bit platforms

From
DSDennis Stosberg <dennis@stosberg.net>
Date
May 11, 2006, 17:36 UTC
Message-ID
<20060511173632.G60c08b4@leonov.stosberg.net>

The offset of an object in the pack is recorded as a 4-byte integer in the index file. When reading the offset from the mmap'ed index in prepare_pack_revindex(), the address is dereferenced as a long*. This works fine as long as the long type is four bytes wide. On NetBSD/sparc64, however, a long is 8 bytes wide and so dereferencing the offset produces garbage.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---

I am not sure whether an int cast or an int32_t cast is more appropriate here. An int is not guaranteed to be four bytes wide, but I don't know of any modern platform where that's not the case. On the other hand int32_t is not necessarily available before C99.

Any opinions?  I wonder why no one has hit this on x86_64...
 pack-objects.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
026b1b2cdd5332f59e15cd8611a49ead3094d08c
diff --git a/pack-objects.c b/pack-objects.c
index 523a1c7..29bda43 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -156,7 +156,7 @@ static void prepare_pack_revindex(struct
 
 	rix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1));
 	for (i = 0; i < num_ent; i++) {
-		long hl = *((long *)(index + 24 * i));
+		long hl = *((int *)(index + 24 * i));
 		rix->revindex[i] = ntohl(hl);
 	}
 	/* This knows the pack format -- the 20-byte trailer
-- 
1.3.2.gbe65
Next: Linus Torvalds
Message 1 of 10 in “Fix git-pack-objects for 64-bit platforms”
  1. Fix git-pack-objects for 64-bit platformsDennis Stosberg, May 11, 2006
  2. Linus TorvaldsMay 11, 2006
  3. Junio C HamanoMay 11, 2006
  4. Linus TorvaldsMay 11, 2006
  5. Linus TorvaldsMay 11, 2006
  6. Junio C HamanoMay 13, 2006
  7. Ben CliffordMay 14, 2006
  8. include header to define uint32_t, necessary on Mac OS XBen Clifford, May 14, 2006
  9. Alex RiesenMay 20, 2006
  10. Linus TorvaldsMay 20, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.