git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] pretty: Fix bug in truncation support for %>, %< and %><

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 29, 2013, 17:55 UTC
Message-ID
<20130429175551.GA24467@google.com>
In-Reply-To
<517C2A68.4030802@ramsay1.demon.co.uk>
Hi,
Ramsay Jones wrote:
> 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).

This is reproducible when running the test suite for 1.8.3-rc0 on some Debian test machines (ARM, ia64, powerpc) using gcc 4.6:

  https://buildd.debian.org/status/logs.php?pkg=git&ver=1%3A1.8.3~rc0-1
Show 13 quoted lines
> 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.
Makes sense.
[...]
Show 8 quoted lines
> 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.

Nice cleanup. I haven't tested the patch but it looks obviously correct and I assume you've tested it, so for what it's worth,

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Previous: Ramsay Jones
Message 4 of 4 in “pretty: Fix bug in truncation support for %>, %< and %><”
  1. pretty: Fix bug in truncation support for %>, %< and %><Ramsay Jones, Apr 27, 2013
  2. Duy NguyenApr 27, 2013
  3. Ramsay JonesApr 29, 2013
  4. Jonathan NiederApr 29, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.