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 --- userdiff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'userdiff.c') diff --git a/userdiff.c b/userdiff.c index e399543823..2b1dab2649 100644 --- a/userdiff.c +++ b/userdiff.c @@ -323,8 +323,7 @@ static int userdiff_find_by_namelen_cb(struct userdiff_driver *driver, { struct find_by_namelen_data *cb_data = priv; - if (!strncmp(driver->name, cb_data->name, cb_data->len) && - !driver->name[cb_data->len]) { + if (!xstrncmpz(driver->name, cb_data->name, cb_data->len)) { cb_data->driver = driver; return 1; /* tell the caller to stop iterating */ } -- cgit v1.2.3