Closed Qiuye-Hua closed 1 year ago
Infer version: v1.1.0-d83ea2caec OS: Ubuntu 20.04 Running command: infer run --pulse g++ test.cpp
infer run --pulse g++ test.cpp
Consider the following simple program test.cpp:
test.cpp
#include <memory> int main() { std::unique_ptr<int> p1(new (std::nothrow) int); if (!p1) { return 1; } std::unique_ptr<int> p2(new (std::nothrow) int); if (!p2) { return 1; } return 0; }
where std::nothrow makes sure that new does not throw exception when there is a problem, but return nullptr instead.
std::nothrow
nullptr
The thing is, Infer/Pulse seems to confuse this syntax with placement new operator, and emit a "Use After Delete" warning for it.
If I run Infer with infer run --pulse -- g++ test.cpp I got:
infer run --pulse -- g++ test.cpp
test.cpp:13: error: Use After Delete accessing memory that was invalidated by delete on line 13. return 1; } return 0; ^ }
test.cpp:13: error: Use After Delete accessing memory that was invalidated by delete on line 13.
delete
@Qiuye-Hua Thank you for the report with clear explanation/examples!
Thank you for the amazingly fast fix! After recompiling Infer with the latest code, the false positives in my project went away :thumbsup: .
Infer version: v1.1.0-d83ea2caec OS: Ubuntu 20.04 Running command:
infer run --pulse g++ test.cpp
Consider the following simple program
test.cpp
:where
std::nothrow
makes sure that new does not throw exception when there is a problem, but returnnullptr
instead.The thing is, Infer/Pulse seems to confuse this syntax with placement new operator, and emit a "Use After Delete" warning for it.
If I run Infer with
infer run --pulse -- g++ test.cpp
I got: