aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>2013-04-27 20:43:36 +0100
committerJunio C Hamano <gitster@pobox.com>2013-04-28 12:09:37 -0700
commit980419b99306b326d44d740a95f3401e169ad943 (patch)
tree00e91639b39ef6af0a3cbfda7be0d14074ba95b8
parent1640632b4f3f69775f04e9e40dfd2fd912e0f458 (diff)
downloadgit-980419b99306b326d44d740a95f3401e169ad943.tar.gz
git-980419b99306b326d44d740a95f3401e169ad943.tar.xz
pretty: Fix bug in truncation support for %>, %< and %><
Some systems experience failures in t4205-*.sh (tests 18-20, 27) which all relate to the use of truncation with the %< padding placeholder. This capability was added in the commit a7f01c6b ("pretty: support truncating in %>, %< and %><", 19-04-2013). The truncation support was implemented with the assistance of a new strbuf function (strbuf_utf8_replace). This function contains the following code: strbuf_attach(sb_src, strbuf_detach(&sb_dst, NULL), sb_dst.len, sb_dst.alloc); Unfortunately, this code is subject to unspecified behaviour. In particular, the order of evaluation of the argument expressions (along with the associated side effects) is not specified by the C standard. Note that the second argument expression is a call to strbuf_detach() which, as a side effect, sets the 'len' and 'alloc' fields of the sb_dst argument to zero. Depending on the order of evaluation of the argument expressions to the strbuf_attach call, this can lead to assigning an empty string to 'sb_src'. In order to remove the undesired behaviour, we replace the above line of code with: strbuf_swap(sb_src, &sb_dst); strbuf_release(&sb_dst); which achieves the desired effect without provoking unspecified behaviour. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Acked-by: Duy Nguyen <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--utf8.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/utf8.c b/utf8.c
index b1e13035f..0d20e0acb 100644
--- a/utf8.c
+++ b/utf8.c
@@ -463,8 +463,8 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
w += n;
}
strbuf_setlen(&sb_dst, dst - sb_dst.buf);
- strbuf_attach(sb_src, strbuf_detach(&sb_dst, NULL),
- sb_dst.len, sb_dst.alloc);
+ strbuf_swap(sb_src, &sb_dst);
+ strbuf_release(&sb_dst);
}
int is_encoding_utf8(const char *name)