@matheusbsbs / matheus-bagliano / commits / d0e50cb4cb
Fork 0

commit: fix pretty-printing of messages with "\nencoding "

The function replace_encoding_header is given the whole commit buffer, including the commit message. When looking for the encoding header, if none was found in the header, it would locate any line in the commit message matching "\nencoding " and remove it. Instead, we now make sure to search only to the end of the header. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jeff King committed Mar 28, 2007 at 17:52 UTC d0e50cb4cb8e0cc8b445a9749547019efaa5703e
1 file changed +5 -2
commit.c
+5 -2
@@ -644,6 +644,7 @@ static char *get_header(const struct commit *commit, const char *key)
644 static char *replace_encoding_header(char *buf, char *encoding)
645 {
646 char *encoding_header = strstr(buf, "\nencoding ");
647 + char *header_end = strstr(buf, "\n\n");
648 char *end_of_encoding_header;
649 int encoding_header_pos;
650 int encoding_header_len;
@@ -651,8 +652,10 @@ static char *replace_encoding_header(char *buf, char *encoding)
652 int need_len;
653 int buflen = strlen(buf) + 1;
654
654 - if (!encoding_header)
655 - return buf; /* should not happen but be defensive */
655 + if (!header_end)
656 + header_end = buf + buflen;
657 + if (!encoding_header || encoding_header >= header_end)
658 + return buf;
659 encoding_header++;
660 end_of_encoding_header = strchr(encoding_header, '\n');
661 if (!end_of_encoding_header)