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

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

From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Date
Apr 29, 2013, 21:29 UTC
Message-ID
<517EE61C.5040802@ramsay1.demon.co.uk>
In-Reply-To
<CACsJy8Dx2tKdQDLw9=i1aM6=uqVBvHYpzq-q+rQE-e7-oJTRcg@mail.gmail.com>
Duy Nguyen wrote:
Show 15 quoted lines
> On Sun, Apr 28, 2013 at 2:43 AM, Ramsay Jones
> <ramsay@ramsay1.demon.co.uk> wrote:
>> 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.
> 
> Thanks for noticing and fixing it.

I didn't notice it; your test noticed it and nagged me to take a look! ;-)

The verbose output from the test made it clear that, rather than the expected truncated output, it was returning an empty string. A quick trip to the debugger clearly showed strbuf_detach() clearing the len and alloc fields of sb_dst, which was then passed to strbuf_attach(). So, I didn't really do much. :-D

>                                   What compiler did you use by the way?
The compiler was gcc, but that doesn't really matter much.

ATB, Ramsay Jones

Previous: Duy NguyenNext: Jonathan Nieder
Message 3 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.