[PATCH 12/21] Use prefixcmp() instead of memcmp() for cleaner code with less magic numbers
Signed-off-by: Johan Herland <johan@herland.net>
---
tag.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/tag.c b/tag.c
index c7c75b3..ac76ec0 100644
--- a/tag.c
+++ b/tag.c
@@ -51,6 +51,13 @@ static int verify_object(unsigned char *sha1, const char *expected_type)
return ret;
}
+/*
+ * Perform parsing and verification of tag object data.
+ *
+ * The 'item' parameter may be set to NULL if only verification is desired.
+ *
+ * The given data _must_ be null-terminated.
+ */
int parse_and_verify_tag_buffer(struct tag *item,
const char *data, const unsigned long size, int thorough_verify)
{
@@ -75,7 +82,7 @@ int parse_and_verify_tag_buffer(struct tag *item,
return error("Tag object failed preliminary size check");
/* Verify object line */
- if (memcmp(data, "object ", 7))
+ if (prefixcmp(data, "object "))
return error("Tag object (@ char 0): "
"Does not start with \"object \"");
@@ -84,7 +91,7 @@ int parse_and_verify_tag_buffer(struct tag *item,
/* Verify type line */
type_line = data + 48;
- if (memcmp(type_line - 1, "\ntype ", 6))
+ if (prefixcmp(type_line - 1, "\ntype "))
return error("Tag object (@ char 47): "
"Could not find \"\\ntype \"");
@@ -94,7 +101,7 @@ int parse_and_verify_tag_buffer(struct tag *item,
return error("Tag object (@ char " PD_FMT "): "
"Could not find \"\\n\" after \"type\"",
type_line - data);
- if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n')
+ if (prefixcmp(tag_line, "tag ") || tag_line[4] == '\n')
return error("Tag object (@ char " PD_FMT "): "
"Could not find \"tag \"", tag_line - data);
@@ -105,7 +112,7 @@ int parse_and_verify_tag_buffer(struct tag *item,
"Could not find \"\\n\" after \"tag\"",
tag_line - data);
if (thorough_verify) {
- if (memcmp(tagger_line, "tagger ", 7) || (tagger_line[7] == '\n'))
+ if (prefixcmp(tagger_line, "tagger ") || (tagger_line[7] == '\n'))
return error("Tag object (@ char " PD_FMT "): "
"Could not find \"tagger \"",
tagger_line - data);
--
1.5.2