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

From: Ramsay Jones <[email-masked]>
Date: Mon, 29 Apr 2013 22:29:00 +0100

Duy Nguyen wrote:
> On Sun, Apr 28, 2013 at 2:43 AM, Ramsay Jones
> <[email-masked]> 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