Skip to content

Commit 049b501

Browse files
committed
Use the content length libgit2 gives us.
Libgit2 documents that the content isn’t NUL-terminated, so we can’t call strlen on it.
1 parent 3b5e9fb commit 049b501

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

generate/templates/manual/src/convenient_patch.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ PatchData *createFromRaw(git_patch *raw) {
8383
}
8484

8585
if (j == 0) {
86-
// calculate strlen only once for the first line of the first hunk.
87-
int calculatedContentLength = strlen(line->content);
86+
int calculatedContentLength = line->content_len;
8887
if (
8988
calculatedContentLength > noNewlineStringLength &&
90-
!strcmp(
89+
!strncmp(
9190
&line->content[calculatedContentLength - noNewlineStringLength],
92-
"\n\\ No newline at end of file\n"
91+
"\n\\ No newline at end of file\n", std::min(calculatedContentLength, noNewlineStringLength)
9392
)) {
9493
EOFFlag = true;
9594
}

0 commit comments

Comments
 (0)