]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pretty: use prefixcmp instead of memcmp on NUL-terminated strings
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Mon, 14 Jan 2013 16:34:56 +0000 (17:34 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2013 17:59:27 +0000 (09:59 -0800)
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>
pretty.c

index 63350af6145248aaaafc131ebbdb4e8a91ae7eb0..94c6a34fa8b1e93a535b3c37fc4aa7e269993645 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -966,7 +966,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
 
                        if (!end)
                                return 0;
-                       if (!memcmp(begin, "auto,", 5)) {
+                       if (!prefixcmp(begin, "auto,")) {
                                if (!want_color(c->pretty_ctx->color))
                                        return end - placeholder + 1;
                                begin += 5;
@@ -1310,7 +1310,7 @@ static void pp_header(const struct pretty_print_context *pp,
                        continue;
                }
 
-               if (!memcmp(line, "parent ", 7)) {
+               if (!prefixcmp(line, "parent ")) {
                        if (linelen != 48)
                                die("bad parent line in commit");
                        continue;
@@ -1334,11 +1334,11 @@ static void pp_header(const struct pretty_print_context *pp,
                 * FULL shows both authors but not dates.
                 * FULLER shows both authors and dates.
                 */
-               if (!memcmp(line, "author ", 7)) {
+               if (!prefixcmp(line, "author ")) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Author", sb, line + 7, encoding);
                }
-               if (!memcmp(line, "committer ", 10) &&
+               if (!prefixcmp(line, "committer ") &&
                    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Commit", sb, line + 10, encoding);