[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)
Chris Cotter via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 4 18:54:46 PST 2025
ccotter wrote:
> 1. How common is this bug?
In one of our internal codebases, a sample of about 1500 files found just over 2% of the files had this bug. As we migrated platforms/standard libraries, the behavior which was previously correct (by chance) changed to be incorrect.
> 2. What happens in practice at runtime?
In practice, the formatted string can be incorrect (but no crash etc). One example is https://godbolt.org/z/3GdnPrsYj
```
char buf[10];
sprintf(buf, "%s", "12");
sprintf(buf, "%s%s", "34", buf);
printf("/%s/\n", buf); // 3434
```
> 3. What are existing ways of detecting this, if any?
None to my knowledge. After finding a couple occurrences of this bug internally, I realized clang-query/clang-tidy could easily catch this.
https://github.com/llvm/llvm-project/pull/114244
More information about the cfe-commits
mailing list