sprintf warning on overlapping output
Martin Sebor
msebor@redhat.com
Tue Sep 27 17:19:00 GMT 2016
On 09/25/2016 03:46 AM, Bernd Edlinger 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 for the suggestion! I had (briefly) looked into this at one
point when I noticed your (or someone else's) bug or comment about
this class of problems. I think the simple case above (where the
pointers are the same) could be detected by the patch but, as others
have already replied, the general problem would require a deep pointer
alias analysis and, IMO, would best be handled under PR35503 or
similar. A work in progress patch for a subset of such cases is
under review here:
https://gcc.gnu.org/ml/gcc-patches/2016-08/msg01853.html
Martin
More information about the Gcc
mailing list