Re: [PATCH] diff: avoid stack-buffer-read-overrun for very long name
On 04/26/2012 06:13 PM, Junio C Hamano wrote:
Show 20 quoted lines
> Jim Meyering<jim@meyering.net> writes:
>
>> What do you think about replacing those two append-if-needed two-liners:
>>
>> if (buffer2.len&& buffer2.buf[buffer2.len - 1] != '/')
>> strbuf_addch(&buffer2, '/');
>>
>> by something that readably encapsulates the idiom:
>>
>> strbuf_append_if_absent (&buffer2, '/');
>>
>> (though the name isn't particularly apt, because you might
>> take "absent" to mean "not anywhere in the string," so maybe
>> strbuf_append_if_not_already_at_end (ugly) or
>> strbuf_append_uniq
>> )
>
> I am not good at names, but strbuf_terminate_with(&buffer2, '/')
> perhaps?
>
"terminate" sounds pretty final though. How about strbuf_ensure_suffixch()?
It embeds the 'ch', marking it as a char argument and provides natural names
for
strbuf_ensure_suffix(buf, char *str);
strbuf_ensure_prefix(buf, char *str);
strbuf_ensure_prefixch(buf, char c);
if those are ever needed.
--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.