Merge branch 'nd/strbuf-utf8-replace'
authorJunio C Hamano <gitster@pobox.com>
Tue, 9 Sep 2014 19:54:02 +0000 (12:54 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Sep 2014 19:54:02 +0000 (12:54 -0700)
* nd/strbuf-utf8-replace:
utf8.c: fix strbuf_utf8_replace() consuming data beyond input string

t/t4205-log-pretty-formats.sh
utf8.c
index 349c531989326eacfe1e1448bfed740d7fd4bd8e..de0cc4a0fd5fe37bb36a3268182d95de3589f4b4 100755 (executable)
@@ -431,6 +431,13 @@ EOF
        test_cmp expected actual
 '
 
+test_expect_success 'strbuf_utf8_replace() not producing NUL' '
+       git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" |
+               test_decode_color |
+               nul_to_q >actual &&
+       ! grep Q actual
+'
+
 # get new digests (with no abbreviations)
 head1=$(git rev-parse --verify HEAD~0) &&
 head2=$(git rev-parse --verify HEAD~1) &&
diff --git a/utf8.c b/utf8.c
index b30790d043aa4b01da00686654dfb615a92e75b6..401a6a509e8b4221a539cec6ad67721fc620d64e 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -382,6 +382,9 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
                        dst += n;
                }
 
+               if (src >= end)
+                       break;
+
                old = src;
                n = utf8_width((const char**)&src, NULL);
                if (!src)       /* broken utf-8, do nothing */