aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2024-02-10 08:43:01 +0100
committerJunio C Hamano <gitster@pobox.com>2024-02-12 09:32:41 -0800
commitf0e578c69cd91a554179c09dab6989f6eb0e2910 (patch)
tree0f0e026d645a86529a80a2237f78329534cd5ba1 /object.c
parent3526e67d917bcd03f317a058208fa02737654637 (diff)
downloadgit-f0e578c69cd91a554179c09dab6989f6eb0e2910.tar.gz
use xstrncmpz()
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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.c')
-rw-r--r--object.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/object.c b/object.c
index 2c61e4c862..e6a1c4d905 100644
--- a/object.c
+++ b/object.c
@@ -47,8 +47,7 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
len = strlen(str);
for (i = 1; i < ARRAY_SIZE(object_type_strings); i++)
- if (!strncmp(str, object_type_strings[i], len) &&
- object_type_strings[i][len] == '\0')
+ if (!xstrncmpz(object_type_strings[i], str, len))
return i;
if (gentle)