pretty: use prefixcmp instead of memcmp on NUL-terminated strings

This conversion avoids the need for magic string length numbers in the code. And unlike memcmp(), prefixcmp() is careful to not run over the end of a string. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jan 14, 2013 at 17:34 UTC 8a692d277795e426167d76d652cf86656c9c162e
1 file changed +4 -4
pretty.c
+4 -4
@@ -966,7 +966,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
966
967 if (!end)
968 return 0;
969 - if (!memcmp(begin, "auto,", 5)) {
969 + if (!prefixcmp(begin, "auto,")) {
970 if (!want_color(c->pretty_ctx->color))
971 return end - placeholder + 1;
972 begin += 5;
@@ -1310,7 +1310,7 @@ static void pp_header(const struct pretty_print_context *pp,
1310 continue;
1311 }
1312
1313 - if (!memcmp(line, "parent ", 7)) {
1313 + if (!prefixcmp(line, "parent ")) {
1314 if (linelen != 48)
1315 die("bad parent line in commit");
1316 continue;
@@ -1334,11 +1334,11 @@ static void pp_header(const struct pretty_print_context *pp,
1334 * FULL shows both authors but not dates.
1335 * FULLER shows both authors and dates.
1336 */
1337 - if (!memcmp(line, "author ", 7)) {
1337 + if (!prefixcmp(line, "author ")) {
1338 strbuf_grow(sb, linelen + 80);
1339 pp_user_info(pp, "Author", sb, line + 7, encoding);
1340 }
1341 - if (!memcmp(line, "committer ", 10) &&
1341 + if (!prefixcmp(line, "committer ") &&
1342 (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
1343 strbuf_grow(sb, linelen + 80);
1344 pp_user_info(pp, "Commit", sb, line + 10, encoding);