{"thread":{"id":"32624","subject":"[PATCH] pretty: use prefixcmp instead of memcmp on NUL-terminated strings","startedAt":"2013-01-14T16:34:56Z","lastAt":"2013-01-14T16:34:56Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"206807","messageId":"50F433B0.3010501@lsrfire.ath.cx","threadId":"32624","inReplyTo":null,"subject":"[PATCH] pretty: use prefixcmp instead of memcmp on NUL-terminated strings","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2013-01-14T16:34:56Z","receivedAt":"2013-01-14T16:34:56Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"This conversion avoids the need for magic string length numbers in the\ncode.  And unlike memcmp(), prefixcmp() is careful to not run over the\nend of a string.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n pretty.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/pretty.c b/pretty.c\nindex 92c839f..01795de 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -966,7 +966,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,\n \n \t\t\tif (!end)\n \t\t\t\treturn 0;\n-\t\t\tif (!memcmp(begin, \"auto,\", 5)) {\n+\t\t\tif (!prefixcmp(begin, \"auto,\")) {\n \t\t\t\tif (!want_color(c->pretty_ctx->color))\n \t\t\t\t\treturn end - placeholder + 1;\n \t\t\t\tbegin += 5;\n@@ -1301,7 +1301,7 @@ static void pp_header(const struct pretty_print_context *pp,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (!memcmp(line, \"parent \", 7)) {\n+\t\tif (!prefixcmp(line, \"parent \")) {\n \t\t\tif (linelen != 48)\n \t\t\t\tdie(\"bad parent line in commit\");\n \t\t\tcontinue;\n@@ -1325,11 +1325,11 @@ static void pp_header(const struct pretty_print_context *pp,\n \t\t * FULL shows both authors but not dates.\n \t\t * FULLER shows both authors and dates.\n \t\t */\n-\t\tif (!memcmp(line, \"author \", 7)) {\n+\t\tif (!prefixcmp(line, \"author \")) {\n \t\t\tstrbuf_grow(sb, linelen + 80);\n \t\t\tpp_user_info(pp, \"Author\", sb, line + 7, encoding);\n \t\t}\n-\t\tif (!memcmp(line, \"committer \", 10) &&\n+\t\tif (!prefixcmp(line, \"committer \") &&\n \t\t    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {\n \t\t\tstrbuf_grow(sb, linelen + 80);\n \t\t\tpp_user_info(pp, \"Commit\", sb, line + 10, encoding);\n-- \n1.8.0\n"}]}