Skip to content

Commit a719ef5

Browse files
committed
commit: always initialize commit message
When parsing a commit, we will treat all bytes left after parsing the headers as the commit message. When no bytes are left, we leave the commit's message uninitialized. While uncommon to have a commit without message, this is the right behavior as Git unfortunately allows for empty commit messages. Given that this scenario is so uncommon, most programs acting on the commit message will never check if the message is actually set, which may lead to errors. To work around the error and not lay the burden of checking for empty commit messages to the developer, initialize the commit message with an empty string when no commit message is given.
1 parent 4974e3a commit a719ef5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/commit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,11 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
459459
buffer = buffer_start + header_len + 1;
460460

461461
/* extract commit message */
462-
if (buffer <= buffer_end) {
462+
if (buffer <= buffer_end)
463463
commit->raw_message = git__strndup(buffer, buffer_end - buffer);
464-
GITERR_CHECK_ALLOC(commit->raw_message);
465-
}
464+
else
465+
commit->raw_message = git__strdup("");
466+
GITERR_CHECK_ALLOC(commit->raw_message);
466467

467468
return 0;
468469

0 commit comments

Comments
 (0)