Commit ef744db382118260cf1a9da998c9bcf9b564bd3b

Stefan Sperling 2020-08-27T10:18:21

in got_object_commit_get_logmsg(), handle log messages which lack '\n' found by tracey's scan-build

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/lib/object_parse.c b/lib/object_parse.c
index 032e903..25e255c 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -475,6 +475,15 @@ got_object_commit_get_logmsg(char **logmsg, struct got_commit_object *commit)
 
 	} while (line);
 
+	if (*logmsg == NULL) {
+		/* log message does not contain \n */
+		*logmsg = strdup(commit->logmsg);
+		if (*logmsg == NULL) {
+			err = got_error_from_errno("strdup");
+			goto done;
+		}
+	}
+
 	/* Trim redundant trailing whitespace. */
 	len = strlen(*logmsg);
 	while (len > 1 && isspace((unsigned char)(*logmsg)[len - 2]) &&