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

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

From
Junio C Hamano <junkio@cox.net>
Date
May 13, 2006, 05:58 UTC
Message-ID
<7viroav534.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0605111218380.3866@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
Show 13 quoted lines
> Since I _do_ have a 64-bit big-endian architecture, I decided to install 
> some of the 64-bit development libraries that I didn't already have, and I 
> added "-m64" to the compiler flags.
>
> All the tests seem to pass with the simple fix (and without it, we do 
> indeed fail at least t5700-clone-reference.sh).
>
> Of course, there might well be something else that doesn't get coverage, 
> but passing all tests is at least a good sign. And since x86-64 has been 
> getting pretty extensive coverage, I don't think we have a lot of 64-bit 
> bugs per se, this one just happened to hide.
>
> 		Linus

Thanks, both. This is what I am thinking of applying (but I am sort of burned-out right now after a two-day meeting with my sponsors, so the real work will be tomorrow).

It takes the uint32_t version but matches another place to use that type instead of "int" (which would not matter in next 10 years perhaps).

-- >8 --
diff --git a/pack-objects.c b/pack-objects.c
index c0acc46..a81d609 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));
+		uint32_t hl = *((uint32_t *)(index + 24 * i));
 		rix->revindex[i] = ntohl(hl);
 	}
 	/* This knows the pack format -- the 20-byte trailer
diff --git a/sha1_file.c b/sha1_file.c
index f2d33af..642c45a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1126,7 +1126,7 @@ int find_pack_entry_one(const unsigned c
 		int mi = (lo + hi) / 2;
 		int cmp = memcmp(index + 24 * mi + 4, sha1, 20);
 		if (!cmp) {
-			e->offset = ntohl(*((int*)(index + 24 * mi)));
+			e->offset = ntohl(*((uint32_t *)(index + 24 * mi)));
 			memcpy(e->sha1, sha1, 20);
 			e->p = p;
 			return 1;
Previous: Linus TorvaldsNext: Ben Clifford
Message 6 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.