Track buffer sizes for static global pointers - #8828
JeewoongKim wants to merge 3 commits into
Conversation
bc87761 to
d7d165a
Compare
|
Thanks for working on this. I'm not sure this approach is feasible though. |
Yes I agree, thanks for looking at Cppcheck.
I assume that is what the last test case with the I fear that the upside of this PR seems pretty small because it only targets main(). it could find problems in some small and simple synthetic test case more or less. more generic heuristics would be appreciated that could find simple bugs in all code. |
|
Thanks for all the feedback! I initially focused too narrowly on the specific reproducer in the ticket, so the solution ended up being too limited. I agree that a more general heuristic would be more useful. I'm looking into an approach that can handle simple cases across functions. |
Replace the main()-specific propagation with tracking for static global pointers that are not modified or escaped. Also handle allocation functions such as malloc in addition to new.
|
I reworked the implementation to use a more general heuristic. I started with internal-linkage globals rather than external-linkage ones, since their modifications This removes |
This PR started from ticket 14934.
The initial implementation propagated the buffer size of a global pointer into
main().Based on the review feedback, I replaced that approach with tracking for static
global pointers that are not modified or escaped within the translation unit.
Allocation functions such as
mallocare also handled in addition tonew.The original 14934 example uses an external-linkage global, which requires additional
reasoning about modification from other translation units. I therefore limited this change
to internal-linkage globals as a conservative first step rather than claiming to fix directly.