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

[PATCH 2/6] show-diff.c: check unreadbale blob.

From
Junio C Hamano <junkio@cox.net>
Date
Apr 18, 2005, 20:34 UTC
Message-ID
<7vr7h7u8n9.fsf@assigned-by-dhcp.cox.net>
[PATCH 2/6] show-diff.c: check unreadbale blob.

This patch fixes show-diff to detect unreadable blob and warn instead of going ahead and crashing.

To be applied on top of:
    [PATCH 1/6] show-diff.c: clean up private buffer use.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 show-diff.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletion(-)
--- a/show-diff.c
+++ b/show-diff.c
@@ -71,6 +71,11 @@ static void show_diff_empty(struct cache
 	unsigned char type[20], *p, *end;
 
 	old = read_sha1_file(ce->sha1, type, &size);
+	if (! old) {
+		error("unable to read blob object for %s (%s)", ce->name,
+		      sha1_to_hex(ce->sha1));
+		return;
+	}
 	if (size > 0) {
 		int startline = 1;
 		int c = 0;
@@ -195,7 +200,11 @@ int main(int argc, char **argv)
 			continue;
 
 		old = read_sha1_file(ce->sha1, type, &size);
-		show_differences(ce->name, old, size);
+		if (! old)
+			error("unable to read blob object for %s (%s)",
+			      ce->name, sha1_to_hex(ce->sha1));
+		else
+			show_differences(ce->name, old, size);
 		free(old);
 	}
 	return 0;
Message 1 of 1 in “show-diff.c: check unreadbale blob.”
  1. 2/6 show-diff.c: check unreadbale blob.Junio C Hamano, Apr 18, 2005

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.