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

Re: [PATCH 5/7] cleanups: Remove unused variable from sha1_file.c

From
Junio C Hamano <junkio@cox.net>
Date
Apr 17, 2006, 21:42 UTC
Message-ID
<7v64l7lw04.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20060417151448.1D99C19B912@sergelap.hallyn.com>
"Serge E. Hallyn" <serue@us.ibm.com> writes:
> Left is assigned to, but never used in sha1_file.c

True, but in this case I suspect it should be used to make sure we have the 20-byte base_sha1 that follows the header in deltified case, perhaps like this:

diff --git a/sha1_file.c b/sha1_file.c
index e3d0113..929f481 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -874,17 +874,19 @@ void packed_object_info_detail(struct pa
 			       unsigned char *base_sha1)
 {
 	struct packed_git *p = e->p;
-	unsigned long offset, left;
+	unsigned long offset;
 	unsigned char *pack;
 	enum object_type kind;
 
 	offset = unpack_object_header(p, e->offset, &kind, size);
 	pack = p->pack_base + offset;
-	left = p->pack_size - offset;
 	if (kind != OBJ_DELTA)
 		*delta_chain_length = 0;
 	else {
 		unsigned int chain_length = 0;
+		if (p->pack_size - 20 < offset)
+			die("pack file %s records an incomplete delta base",
+			    p->pack_name);
 		memcpy(base_sha1, pack, 20);
 		do {
 			struct pack_entry base_ent;
Previous: Serge E. HallynNext: Serge E. Hallyn
Message 9 of 13 in “cleanups: intro”
  1. 0/7 cleanups: introSerge E. Hallyn, Apr 17, 2006
  2. 1/7 cleanups: Fix resource leak and buffer overrun in daemon.cSerge E. Hallyn, Apr 17, 2006
  3. Junio C HamanoApr 17, 2006
  4. Serge E. HallynApr 18, 2006
  5. Junio C HamanoApr 18, 2006
  6. 2/7 cleanups: Fix potential bugs in connect.cSerge E. Hallyn, Apr 17, 2006
  7. 3/7 cleanups: Remove unused vars from combine-diff.cSerge E. Hallyn, Apr 17, 2006
  8. 5/7 cleanups: Remove unused variable from sha1_file.cSerge E. Hallyn, Apr 17, 2006
  9. Junio C HamanoApr 17, 2006
  10. 6/7 cleanups: prevent leak of two strduped strings in config.cSerge E. Hallyn, Apr 17, 2006
  11. 4/7 cleanups: Remove impossible case in quote.cSerge E. Hallyn, Apr 17, 2006
  12. 7/7 cleanups: remove unused variable from exec_cmd.cSerge E. Hallyn, Apr 17, 2006
  13. Junio C HamanoApr 17, 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.