Skip to content

Commit 8a692d2

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3082517 commit 8a692d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pretty.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
966966

967967
if (!end)
968968
return 0;
969-
if (!memcmp(begin, "auto,", 5)) {
969+
if (!prefixcmp(begin, "auto,")) {
970970
if (!want_color(c->pretty_ctx->color))
971971
return end - placeholder + 1;
972972
begin += 5;
@@ -1310,7 +1310,7 @@ static void pp_header(const struct pretty_print_context *pp,
13101310
continue;
13111311
}
13121312

1313-
if (!memcmp(line, "parent ", 7)) {
1313+
if (!prefixcmp(line, "parent ")) {
13141314
if (linelen != 48)
13151315
die("bad parent line in commit");
13161316
continue;
@@ -1334,11 +1334,11 @@ static void pp_header(const struct pretty_print_context *pp,
13341334
* FULL shows both authors but not dates.
13351335
* FULLER shows both authors and dates.
13361336
*/
1337-
if (!memcmp(line, "author ", 7)) {
1337+
if (!prefixcmp(line, "author ")) {
13381338
strbuf_grow(sb, linelen + 80);
13391339
pp_user_info(pp, "Author", sb, line + 7, encoding);
13401340
}
1341-
if (!memcmp(line, "committer ", 10) &&
1341+
if (!prefixcmp(line, "committer ") &&
13421342
(pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
13431343
strbuf_grow(sb, linelen + 80);
13441344
pp_user_info(pp, "Commit", sb, line + 10, encoding);

0 commit comments

Comments
 (0)