summaryrefslogtreecommitdiff
path: root/ws.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2023-01-07 13:26:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-01-08 01:34:37 (GMT)
commitd43b99322bd0ca4a371901bcf6705f1282143a2b (patch)
tree7c114210e465f0e2bddfc25b2cc281521c4e65b0 /ws.c
parent20869d1a1d30e9a64c66953a0f4c7245089009cf (diff)
downloadgit-d43b99322bd0ca4a371901bcf6705f1282143a2b.zip
git-d43b99322bd0ca4a371901bcf6705f1282143a2b.tar.gz
git-d43b99322bd0ca4a371901bcf6705f1282143a2b.tar.bz2
convert trivial uses of strncmp() to skip_prefix()
As with the previous patch, using skip_prefix() is more readable and less error-prone than a raw strncmp(), because it avoids a manually-computed length. These cases differ from the previous patch that uses starts_with() because they care about the value after the matched prefix. We can convert these to use skip_prefix() by introducing an extra variable to hold the out-pointer. Note in the case in ws.c that to get rid of the magic number "9" completely, we also switch out "len" for recomputing the pointer difference. These are equivalent because "len" is always "ep - string". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ws.c')
-rw-r--r--ws.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ws.c b/ws.c
index 46a77bc..903bfcd 100644
--- a/ws.c
+++ b/ws.c
@@ -29,6 +29,7 @@ unsigned parse_whitespace_rule(const char *string)
int i;
size_t len;
const char *ep;
+ const char *arg;
int negated = 0;
string = string + strspn(string, ", \t\n\r");
@@ -52,15 +53,15 @@ unsigned parse_whitespace_rule(const char *string)
rule |= whitespace_rule_names[i].rule_bits;
break;
}
- if (strncmp(string, "tabwidth=", 9) == 0) {
- unsigned tabwidth = atoi(string + 9);
+ if (skip_prefix(string, "tabwidth=", &arg)) {
+ unsigned tabwidth = atoi(arg);
if (0 < tabwidth && tabwidth < 0100) {
rule &= ~WS_TAB_WIDTH_MASK;
rule |= tabwidth;
}
else
warning("tabwidth %.*s out of range",
- (int)(len - 9), string + 9);
+ (int)(ep - arg), arg);
}
string = ep;
}