When checking if a string begins with a constant string, using
starts_with() indicates the intention of the check more clearly and is
less error-prone than calling !memcmp() with an explicit byte count.
Signed-off-by: Quint Guvernator quintus.pub...@gmail.com
---
builtin/apply.c| 4 ++--
builtin/for-each-ref.c | 2 +-
builtin/mktag.c| 2 +-
builtin/patch-id.c | 10 +-
connect.c | 4 ++--
imap-send.c| 6 +++---
remote.c | 2 +-
7 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 0189523..826b3e2 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1631,7 +1631,7 @@ static int parse_fragment(const char *line, unsigned long
size,
* l10n of \ No newline... is at least that long.
*/
case '\\':
- if (len 12 || memcmp(line, \\ , 2))
+ if (len 12 || !starts_with(line, \\ ))
return -1;
break;
}
@@ -1646,7 +1646,7 @@ static int parse_fragment(const char *line, unsigned long
size,
* it in the above loop because we hit oldlines == newlines == 0
* before seeing it.
*/
- if (12 size !memcmp(line, \\ , 2))
+ if (12 size starts_with(line, \\ ))
offset += linelen(line, size);
patch-lines_added += added;
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 3e1d5c3..4135980 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -193,7 +193,7 @@ static int verify_format(const char *format)
at = parse_atom(sp + 2, ep);
cp = ep + 1;
- if (!memcmp(used_atom[at], color:, 6))
+ if (starts_with(used_atom[at], color:))
need_color_reset_at_eol = !!strcmp(used_atom[at],
color_reset);
}
return 0;
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 640ab64..d2d9310 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -57,7 +57,7 @@ static int verify_tag(char *buffer, unsigned long size)
/* Verify type line */
type_line = object + 48;
- if (memcmp(type_line - 1, \ntype , 6))
+ if (!starts_with(type_line - 1, \ntype ))
return error(char%d: could not find \\\ntype \, 47);
/* Verify tag-line */
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 3cfe02d..23ef424 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -81,14 +81,14 @@ static int get_one_patchid(unsigned char *next_sha1,
git_SHA_CTX *ctx, struct st
}
/* Ignore commit comments */
- if (!patchlen memcmp(line, diff , 5))
+ if (!patchlen !starts_with(line, diff ))
continue;
/* Parsing diff header? */
if (before == -1) {
- if (!memcmp(line, index , 6))
+ if (starts_with(line, index ))
continue;
- else if (!memcmp(line, --- , 4))
+ else if (starts_with(line, --- ))
before = after = 1;
else if (!isalpha(line[0]))
break;
@@ -96,14 +96,14 @@ static int get_one_patchid(unsigned char *next_sha1,
git_SHA_CTX *ctx, struct st
/* Looking for a valid hunk header? */
if (before == 0 after == 0) {
- if (!memcmp(line, @@ -, 4)) {
+ if (starts_with(line, @@ -)) {
/* Parse next hunk, but ignore line numbers. */
scan_hunk_header(line, before, after);
continue;
}
/* Split at the end of the patch. */
- if (memcmp(line, diff , 5))
+ if (!starts_with(line, diff ))
break;
/* Else we're parsing another header. */
diff --git a/connect.c b/connect.c
index 4150412..5ae2aaa 100644
--- a/connect.c
+++ b/connect.c
@@ -30,11 +30,11 @@ static int check_ref(const char *name, int len, unsigned
int flags)
return 0;
/* REF_HEADS means that we want regular branch heads */
- if ((flags REF_HEADS) !memcmp(name, heads/, 6))
+ if ((flags REF_HEADS) starts_with(name, heads/))
return 1;
/* REF_TAGS means that we want tags */
- if ((flags REF_TAGS) !memcmp(name, tags/, 5))
+ if ((flags REF_TAGS) starts_with(name, tags/))
return 1;
/* All type bits clear means that we are ok with anything */
diff --git a/imap-send.c b/imap-send.c
index 0bc6f7f..019de18 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -524,7