Skip to content

Commit 2d10545

Browse files
rscharfegitster
authored andcommitted
apply: use strcmp(3) for comparing strings in gitdiff_verify_name()
We don't know the length of the C string "another". It could be shorter than "name", which we compare it to using memchr(3). Call strcmp(3) instead to avoid running over the end of the former, and get rid of a strlen(3) call as a bonus. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8bc172e commit 2d10545

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

apply.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,12 @@ static int gitdiff_verify_name(struct apply_state *state,
956956
}
957957

958958
if (*name) {
959-
int len = strlen(*name);
960959
char *another;
961960
if (isnull)
962961
return error(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
963962
*name, state->linenr);
964963
another = find_name(state, line, NULL, state->p_value, TERM_TAB);
965-
if (!another || memcmp(another, *name, len + 1)) {
964+
if (!another || strcmp(another, *name)) {
966965
free(another);
967966
return error((side == DIFF_NEW_NAME) ?
968967
_("git apply: bad git-diff - inconsistent new filename on line %d") :

0 commit comments

Comments
 (0)