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

[PATCH 1/2] blame: check return value from read_sha1_file()

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 25, 2007, 08:30 UTC
Message-ID
<7v7ink6mpf.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20070825072604.GA20155@spearce.org>
(Trivial #1).
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-blame.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index 0519339..dc88a95 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -98,6 +98,10 @@ static char *fill_origin_blob(struct origin *o, mmfile_t *file)
 		num_read_blob++;
 		file->ptr = read_sha1_file(o->blob_sha1, &type,
 					   (unsigned long *)(&(file->size)));
+		if (!file->ptr)
+			die("Cannot read blob %s for path %s",
+			    sha1_to_hex(o->blob_sha1),
+			    o->path);
 		o->file = *file;
 	}
 	else
@@ -1384,6 +1388,9 @@ static void get_commit_info(struct commit *commit,
 		unsigned long size;
 		commit->buffer =
 			read_sha1_file(commit->object.sha1, &type, &size);
+		if (!commit->buffer)
+			die("Cannot read commit %s",
+			    sha1_to_hex(commit->object.sha1));
 	}
 	ret->author = author_buf;
 	get_ac_line(commit->buffer, "\nauthor ",
@@ -2382,6 +2389,10 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 
 		sb.final_buf = read_sha1_file(o->blob_sha1, &type,
 					      &sb.final_buf_size);
+		if (!sb.final_buf)
+			die("Cannot read blob %s for path %s",
+			    sha1_to_hex(o->blob_sha1),
+			    path);
 	}
 	num_read_blob++;
 	lno = prepare_lines(&sb);
-- 
1.5.3.rc6.23.g0058
Previous: Shawn O. PearceNext: Junio C Hamano
Message 2 of 5 in “Don't segfault if we failed to inflate a packed delta”
  1. Don't segfault if we failed to inflate a packed deltaShawn O. Pearce, Aug 25, 2007
  2. 1/2 blame: check return value from read_sha1_file()Junio C Hamano, Aug 25, 2007
  3. 2/2 pack-objects: check return value from read_sha1_file()Junio C Hamano, Aug 25, 2007
  4. Linus TorvaldsAug 25, 2007
  5. Junio C HamanoAug 25, 2007

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.