From 145136a95a8755528aa012a4ce0ed50d1ec39e24 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 30 Jan 2020 11:35:46 -0800 Subject: C: use skip_prefix() to avoid hardcoded string length We often skip an optional prefix in a string with a hardcoded constant, e.g. if (starts_with(string, "prefix")) string += 6; which is less error prone when written skip_prefix(string, "prefix", &string); Note that this changes a few error messages from "git reflog expire --expire=nonsense.timestamp", which used to complain by saying '--expire=nonsense.timestamp' is not a valid timestamp but with this change, we say 'nonsense.timestamp' is not a valid timestamp which is more technically correct (the string with --expire= as a prefix obviously cannot be a valid timestamp, but the error is about the part of the input without that prefix). Helped-by: Jeff King Signed-off-by: Junio C Hamano --- transport-helper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'transport-helper.c') diff --git a/transport-helper.c b/transport-helper.c index 413d9d873e..20a7185ec4 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -404,11 +404,12 @@ static int fetch_with_fetch(struct transport *transport, sendline(data, &buf); while (1) { + const char *name; + if (recvline(data, &buf)) exit(128); - if (starts_with(buf.buf, "lock ")) { - const char *name = buf.buf + 5; + if (skip_prefix(buf.buf, "lock ", &name)) { if (transport->pack_lockfile) warning(_("%s also locked %s"), data->name, name); else -- cgit v1.2.3