summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-10-07 09:31:41 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2016-11-03 09:20:55 +0100
commit821042b673675546a265827ea184c6fa14e0623d (patch)
tree7abad8bc55eccd3c188b3c4c411cef171750a9ae
parentdfc2c713433b3a932e4d8b648738e3b63086baec (diff)
downloadlibgit2-cmn/update-v24.tar.gz
commit: always initialize commit messagecmn/update-v24
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.
-rw-r--r--src/commit.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/commit.c b/src/commit.c
index 5ed9c474d..ade4e10b5 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -410,10 +410,11 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
buffer = buffer_start + header_len + 1;
/* extract commit message */
- if (buffer <= buffer_end) {
+ if (buffer <= buffer_end)
commit->raw_message = git__strndup(buffer, buffer_end - buffer);
- GITERR_CHECK_ALLOC(commit->raw_message);
- }
+ else
+ commit->raw_message = git__strdup("");
+ GITERR_CHECK_ALLOC(commit->raw_message);
return 0;