Skip to content

Commit bc2c50f

Browse files
committed
Merge branch 'rs/apply-avoid-over-reading' into maint
Code cleanup. * rs/apply-avoid-over-reading: apply: use strcmp(3) for comparing strings in gitdiff_verify_name() apply: use starts_with() in gitdiff_verify_name()
2 parents 2187e11 + 2d10545 commit bc2c50f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

apply.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,22 +972,20 @@ static int gitdiff_verify_name(struct apply_state *state,
972972
}
973973

974974
if (*name) {
975-
int len = strlen(*name);
976975
char *another;
977976
if (isnull)
978977
return error(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
979978
*name, state->linenr);
980979
another = find_name(state, line, NULL, state->p_value, TERM_TAB);
981-
if (!another || memcmp(another, *name, len + 1)) {
980+
if (!another || strcmp(another, *name)) {
982981
free(another);
983982
return error((side == DIFF_NEW_NAME) ?
984983
_("git apply: bad git-diff - inconsistent new filename on line %d") :
985984
_("git apply: bad git-diff - inconsistent old filename on line %d"), state->linenr);
986985
}
987986
free(another);
988987
} else {
989-
/* expect "/dev/null" */
990-
if (memcmp("/dev/null", line, 9) || line[9] != '\n')
988+
if (!starts_with(line, "/dev/null\n"))
991989
return error(_("git apply: bad git-diff - expected /dev/null on line %d"), state->linenr);
992990
}
993991

0 commit comments

Comments
 (0)