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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 8, 2017 at 10:58 UTC 2d105451c0768fc3e9600dec7bca2376f482521e
1 file changed +1 -2
apply.c
+1 -2
@@ -956,13 +956,12 @@ static int gitdiff_verify_name(struct apply_state *state,
956 }
957
958 if (*name) {
959 - int len = strlen(*name);
959 char *another;
960 if (isnull)
961 return error(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
962 *name, state->linenr);
963 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)) {
965 free(another);
966 return error((side == DIFF_NEW_NAME) ?
967 _("git apply: bad git-diff - inconsistent new filename on line %d") :