[PATCH] Set behavior of sprintf-like functions with overlapping source and destination

Siddhesh Poyarekar siddhesh@gotplt.org
Thu Dec 27 01:31:00 GMT 2018


On 27/12/18 12:26 AM, Paul Eggert wrote:
>> 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.

Turns out the compiler does identify aliases in this case  (although in 
a very generic way because of which the warning may not be super-clear 
to a lot of devs at first glance):

foo.c:9:11: warning: passing argument 1 to restrict-qualified parameter 
aliases with argument 3 [-Wrestrict]
    sprintf(buf, "%sCD", buf);
            ^~~          ~~~

So I suppose we have this part covered.

Siddhesh



More information about the Libc-alpha mailing list