Skip to content

Commit

Permalink
Merge branch 'nd/strbuf-utf8-replace'
Browse files Browse the repository at this point in the history
* nd/strbuf-utf8-replace:
  utf8.c: fix strbuf_utf8_replace() consuming data beyond input string
  • Loading branch information
Junio C Hamano committed Sep 9, 2014
2 parents 27fbcf8 + 4308759 commit 1764e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions t/t4205-log-pretty-formats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
3 changes: 3 additions & 0 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 1764e81

Please sign in to comment.