{"thread":{"id":"108","subject":"[PATCH 2/6] show-diff.c: check unreadbale blob.","startedAt":"2005-04-18T20:34:02Z","lastAt":"2005-04-18T20:34:02Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"687","messageId":"7vr7h7u8n9.fsf@assigned-by-dhcp.cox.net","threadId":"108","inReplyTo":null,"subject":"[PATCH 2/6] show-diff.c: check unreadbale blob.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-04-18T20:34:02Z","receivedAt":"2005-04-18T20:34:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"[PATCH 2/6] show-diff.c: check unreadbale blob.\n\nThis patch fixes show-diff to detect unreadable blob and warn\ninstead of going ahead and crashing.\n\nTo be applied on top of:\n\n    [PATCH 1/6] show-diff.c: clean up private buffer use.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n show-diff.c |   11 ++++++++++-\n 1 files changed, 10 insertions(+), 1 deletion(-)\n\n--- a/show-diff.c\n+++ b/show-diff.c\n@@ -71,6 +71,11 @@ static void show_diff_empty(struct cache\n \tunsigned char type[20], *p, *end;\n \n \told = read_sha1_file(ce->sha1, type, &size);\n+\tif (! old) {\n+\t\terror(\"unable to read blob object for %s (%s)\", ce->name,\n+\t\t      sha1_to_hex(ce->sha1));\n+\t\treturn;\n+\t}\n \tif (size > 0) {\n \t\tint startline = 1;\n \t\tint c = 0;\n@@ -195,7 +200,11 @@ int main(int argc, char **argv)\n \t\t\tcontinue;\n \n \t\told = read_sha1_file(ce->sha1, type, &size);\n-\t\tshow_differences(ce->name, old, size);\n+\t\tif (! old)\n+\t\t\terror(\"unable to read blob object for %s (%s)\",\n+\t\t\t      ce->name, sha1_to_hex(ce->sha1));\n+\t\telse\n+\t\t\tshow_differences(ce->name, old, size);\n \t\tfree(old);\n \t}\n \treturn 0;\n\n"}]}