This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: sprintf warning on overlapping output
- From: Eric Gallager <egall at gwmail dot gwu dot edu>
- To: Bernd Edlinger <bernd at edlinger-online dot de>
- Cc: Martin Sebor <msebor at redhat dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sun, 25 Sep 2016 09:28:44 -0400
- Subject: Re: sprintf warning on overlapping output
- Authentication-results: sourceware.org; auth=none
- References: <57E79CD9.2080903@edlinger-online.de>
On 9/25/16, Bernd Edlinger <bernd@edlinger-online.de> wrote:
> Hi Martin,
>
> in the past I have seen (and fixed) code like
>
> sprintf(buf, "%s %d", buf, x);
>
> that may possibly work by chance, but usually
> produces undefined results.
>
> Do you see a way to enhance the warning for cases
> where the output buffer overlaps an input buffer?
>
>
>
> Thanks
> Bernd.
>
I was testing Prathamesh's -Wrestrict patch, and it caught a few cases
like that:
https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00027.html
Eric