this sort of code is analyzed properly and throws no errors typedef char ** STR; void f() { void *buf; STR s = (STR) &buf; } however, if the typedefs are not present and cppcheck doesn't know what STR is void f() { void *buf; STR s = (STR) &buf; } iscast() in tokenlist.cpp returns false for (STR) and the & is parsed as a bitwise AND, instead of the address-of operator. Because the & is a binary operator on unitialized data, this example throws a false positive: examples/uninit.c:3:19: error: Uninitialized...
in cli/filelister.cpp:addFiles2 there is struct stat file_stat; if (stat(path.c_str(), &file_stat) == -1) return ""; // TODO: return error? if we returned an error here we could help users who are in this situation. I don't know what situation there would be for a user to specify the analysis of a nonexistent file. The most common thing would probably be people mistyping the name of a file or something similar, in which case proceeding as usual is probably an annoying behavior.
What version of cppcheck did you use to create this bug? I tried to reproduce this using the current master branch and this issue you describe didn't happen, even with --library=qt with --debug it looks like its working properly now: using the first namespace Checking examples/namespace.cpp ... ##file examples/namespace.cpp 3: namespace TetheringState 4: { 5: constexpr int NUMBER_OF_RESPONSE_FIELDS@var1 = 2 ; 6: } 7: 8: namespace TetheringStateV2 9: { 10: constexpr int NUMBER_OF_RESPONSE_FIELDS@var2...
Hah I was just trying to make a minimal example for the dangling lifetime issue. Here is what I have right now: class A {}; std::unique_ptr<A> saved; A *f(int x) { std::unique_ptr<A> tmp = std::make_unique<A>(); A *ptr = tmp.get(); saved = std::move(tmp); return ptr; } expected result: no errors actual result: error: Returning pointer to local variable 'tmp' that will be invalid when returning. [returnDanglingLifetime]
Hi all, Aaron again :) on the code: void f() { int idx; int arr[3]; for (idx = 0; idx < 3; idx++) { break; } arr[idx] = 0; } cppcheck reports examples/breakfor.c:7:8: error: Array 'arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds] arr[idx] = 0; ^ examples/breakfor.c:4:23: note: Assuming that condition 'idx<3' is not redundant for (idx = 0; idx < 3; idx++) { ^ examples/breakfor.c:7:8: note: Array index out of bounds arr[idx] = 0; ^ This is a false positive because in the...
I made a PR: https://github.com/cppcheck-opensource/cppcheck/pull/8765 Thanks! Aaron
Hi all This is my first time posting here so apologies if I mess something up. Also I am very junior (first internship) so I am sorry if I make silly mistakes! I was using cppcheck on a codebase and found a recurring issue where if memory or a resource is stored in a class/struct, cppcheck will throw a memory leak error even if its deallocated in the objects destructor. #include <cstdlib> #include <unistd.h> class TempFile { public: TempFile(int fd) { m_fd = fd; } ~TempFile() { if (m_fd >= 0) close(m_fd);...