[PATCH] Set behavior of sprintf-like functions with overlapping source and destination
Paul Eggert
eggert@cs.ucla.edu
Wed Dec 26 22:22:00 GMT 2018
Siddhesh Poyarekar wrote:
> On 21/12/18 3:47 AM, Paul Eggert wrote:
>>> /* Test the sprintf (buf, "%s", buf) does not override buf.
>>
>> I'm leery of adding this test case, as it tests undefined behavior that the
>> glibc manual does not document as an extension (and it shouldn't be documented
>> either).
>>
>> Traditionally we didn't worry about breaking code like PughUtils.c's
>> 'sprintf(mess,"%s %d",mess,...)' under the principle that such code was
>> already broken. Why depart from that tradition here?
>
> Is the disagreement here only about testing UB or also about retaining old
> behaviour in case of UB?
Primarily the former. I don't want us to test for and/or guarantee support for
this particular implementation of UB. (Although I'm not happy about the extra
code inserted into every printf call to deal with this situation, it's not like
printf is particularly fast now....)
> If it's just the former then we could make forward
> progress by just removing the UB test case and just keeping the ub-chk test case.
>
> It may not be too hard for the compiler to see this undefined behaviour and warn
> about it either, at least in some trivial cases...
Yes, that'd be good.
More information about the Libc-alpha
mailing list