{"thread":{"id":"5895","subject":"[PATCH] commit: fix a segfault when displaying a commit with unreachable parents","startedAt":"2006-10-11T23:16:02Z","lastAt":"2006-10-11T23:16:02Z","messageCount":1,"participants":["Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"28647","messageId":"11606085621137-git-send-email-normalperson@yhbt.net","threadId":"5895","inReplyTo":null,"subject":"[PATCH] commit: fix a segfault when displaying a commit with unreachable parents","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-10-11T23:16:02Z","receivedAt":"2006-10-11T23:16:02Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"I was running git show on various commits found by fsck-objects\nwhen I found this bug.  Since find_unique_abbrev() cannot find\nan abbreviation for an object not in the database, it will\nreturn NULL, which is bad to run strlen() on.  So instead, we'll\njust display the unabbreviated sha1 that we referenced in the\ncommit.\n\nI'm not sure that this is the best 'fix' for it because the\ncommit I was trying to show was broken, but I don't think a\nprogram should segfault even if the user tries to do something\nstupid.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n commit.c |   11 +++++++----\n 1 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 5b6e082..a6d543e 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -548,10 +548,13 @@ static int add_merge_info(enum cmit_fmt \n \n \twhile (parent) {\n \t\tstruct commit *p = parent->item;\n-\t\tconst char *hex = abbrev\n-\t\t\t? find_unique_abbrev(p->object.sha1, abbrev)\n-\t\t\t: sha1_to_hex(p->object.sha1);\n-\t\tconst char *dots = (abbrev && strlen(hex) != 40) ? \"...\" : \"\";\n+\t\tconst char *hex = NULL;\n+\t\tconst char *dots;\n+\t\tif (abbrev)\n+\t\t\thex = find_unique_abbrev(p->object.sha1, abbrev);\n+\t\tif (!hex)\n+\t\t\thex = sha1_to_hex(p->object.sha1);\n+\t\tdots = (abbrev && strlen(hex) != 40) ?  \"...\" : \"\";\n \t\tparent = parent->next;\n \n \t\toffset += sprintf(buf + offset, \" %s%s\", hex, dots);\n-- \n1.4.3.rc2.g823d6-dirty\n"}]}