Skip to content

Commit 42df674

Browse files
committed
Merge pull request #908 from nodegit/fix-segfault-convenient-patch
Don't check for \\ No newline at end of file\n if it can't exist
2 parents 895d5e6 + 59ecdf0 commit 42df674

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

generate/templates/manual/src/convenient_patch.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ PatchData *createFromRaw(git_patch *raw) {
7575
const git_diff_line *line;
7676
git_patch_get_line_in_hunk(&line, raw, i, j);
7777

78-
if (
79-
j == 0 &&
80-
!strcmp(
81-
&line->content[strlen(line->content) - 29],
82-
"\n\\ No newline at end of file\n"
83-
)) {
84-
EOFFlag = true;
78+
if (j == 0) {
79+
// calculate strlen only once for the first line of the first hunk.
80+
int calculatedContentLength = strlen(line->content);
81+
if (
82+
calculatedContentLength > 29 &&
83+
!strcmp(
84+
&line->content[calculatedContentLength - 29],
85+
"\n\\ No newline at end of file\n"
86+
)) {
87+
EOFFlag = true;
88+
}
8589
}
8690

8791
storeLine->origin = line->origin;

0 commit comments

Comments
 (0)