From f0e578c69cd91a554179c09dab6989f6eb0e2910 Mon Sep 17 00:00:00 2001 From: RenĂ© Scharfe Date: Sat, 10 Feb 2024 08:43:01 +0100 Subject: use xstrncmpz() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add and apply a semantic patch for calling xstrncmpz() to compare a NUL-terminated string with a buffer of a known length instead of using strncmp() and checking the terminating NUL explicitly. This simplifies callers by reducing code duplication. I had to adjust remote.c manually because Coccinelle inexplicably changed the indent of the else branches. Signed-off-by: RenĂ© Scharfe Signed-off-by: Junio C Hamano --- builtin/merge.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'builtin/merge.c') diff --git a/builtin/merge.c b/builtin/merge.c index ebbe05033e..b390a8f6bc 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -192,8 +192,7 @@ static struct strategy *get_strategy(const char *name) int j, found = 0; struct cmdname *ent = main_cmds.names[i]; for (j = 0; !found && j < ARRAY_SIZE(all_strategy); j++) - if (!strncmp(ent->name, all_strategy[j].name, ent->len) - && !all_strategy[j].name[ent->len]) + if (!xstrncmpz(all_strategy[j].name, ent->name, ent->len)) found = 1; if (!found) add_cmdname(¬_strategies, ent->name, ent->len); -- cgit v1.2.3