Activity for cppcheck
-
CHR posted a comment on discussion Development
It looks like merged PRs are not flushed out, e.g. https://github.com/cppcheck-opensource/cppcheck/pull/8934
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15126
-
Joel Shuman posted a comment on discussion General Discussion
I also should mention that cppcheck 2.19.0 did not have this false positive.
-
Joel Shuman posted a comment on discussion General Discussion
Hello, We ran into a corner-case false-positive syntaxError I'd like to report. It is similar to this which was fixed long ago. In this corner-case, using the override keyword causes the false positive. struct base { virtual ~base() = default; virtual void foo() try {} catch (...) {}; }; struct special : base { void foo() override // This override causes the try on the next line to false fail. try {} catch (...) {} }; int main() { special s; s.foo(); return 0; } I am testing with cppcheck 2.22.0....
-
john borland posted a comment on discussion Development
I wrote a couple of bash scripts to run over the weekend to do code coverage of the released 2.22.0 version of cppcheck with debian packages (It's still running). I wasn't sure how you knows a package had C/C++ code in them, so I just pulled from the following 9 PR's below and hopped for the best. 2026-02-18_12-13-45-d234d745fefe-results.txt 2026-10-05_07-31-15-7f232989d1f9-results.txt 2026-10-09_20-01-23-da724f2e5700-results.txt 2026-09-08_13-51-12-2a0c507aec8b-results.txt 2026-10-05_14-59-08-c5bef2ae24cd-results.txt...
-
XHATN posted a comment on discussion General Discussion
I found that cppcheck’s addon dump can produce MISRA diagnostics in a non-source order. In SymbolDatabase::printXml() (lib/symboldatabase.cpp), variables are collected in std::set<const Variable*> before the <variables> XML section is written. This orders records by object-pointer address instead of a stable source key. The MISRA addon reads that XML order into data.variables, and Rule 9.3 then iterates data.variables directly. Therefore Rule 9.3 diagnostics can be reported in a different order from...
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15103
-
Dan Workman posted a comment on discussion General Discussion
Found in cppcheck 2.22 Running cppcheck --enable=style --std=c++17 --template=gcc repro.cpp on #include <functional> #include <vector> struct Item {}; void example() { Item value; auto& ref = value; std::vector<std::reference_wrapper<Item>> refs{ref}; } gives Variable 'ref' can be declared as reference to const [constVariableReference]
-
john borland posted a comment on discussion Development
Depending on how many tokens you want to use here are other things you can ask AI about a PR. Will this PR require the cppcheck manual to change? if yes which sections. What unit test cover these changes? if no unit test is found can please write one. What do you think the intent of this PR is?
-
john borland posted a comment on discussion Development
To me this talk has lived rent free in my brain since 2012 https://youtu.be/5wwKjdvPxa8 its about how CI can be used as a code reviewer. Most CI systems are pass fail. But there tea leaves that often go unnoticed. I think in the age of AI its probably a good idea to use AI as a first pass aproach to keep from getting overwhelmed. I even know of an open source project that is talking internally about poising their skill file to say all issues must be written using Shakespearen English. That way they...
-
CHR posted a comment on discussion Development
Please provide feedback. Do you think I should tweak the reports or output somehow? Having a link to the actual PR would be nice (instead of/additional to linking to the AWS files). How is reanalysis supposed to work? E.g. for #8918, the latest commit shown is from Oct 5, while there is a newer commit from Oct 7 already (https://github.com/cppcheck-opensource/cppcheck/pull/8918/changes/97161058bc8dbc7b18acf69ae1cf324a21507f65).
-
john borland posted a comment on discussion Development
I think one thing that matters a lot is how easy is it for you to integrate into your workflow. For me given that I learned to code inside a unix terminal and never evolved to using an IDE to code with AI isnt to difficult to record my interactions with. The script command https://www.redhat.com/en/blog/linux-script-command does alot of the heavy lifting. I also write a bit of data like starting and stopping git hash as well as the ai model version and token usage to a file. That way I can restore...
-
Daniel Marjamäki posted a comment on discussion Development
One thing I recomend when it comes to AI is to keep internal metrics so that you can better help you evluete AI future solutions how do you suggest that I do that?
-
john borland posted a comment on discussion Development
One thing I recomend when it comes to AI is to keep internal metrics so that you can better help you evluete AI future solutions. That includes keeping track of the work done by AI which you can put a tag in an issue or a tag in the git commit message. You will want to be able to match that tag to a prompt, token usage and model version number. That way if you want to make changes later to your AI process you can test it aginst past solutions to see if the change adds value. On a side note one thing...
-
CHR modified a comment on discussion Development
Good idea 👍 Having the user name in a column would be nice. Also, some PRs seem to be missing. Are they still being processed?
-
Daniel Marjamäki posted a comment on discussion Development
I am adding AI reviews in opensource cppcheck AI is not perfect there is some bad review comments. As a PR author you can reject such comments by resolving them. My idea going forward is that I will not review a PR manually if there are open AI reviews. I want to limit the amount of manual reviews because; for reviewers it takes a lot of time. I don't want to waste time on nits that we could avoid automatically. I have to re-review the whole PR every time I see some nits. for developers manual reviews...
-
Daniel Marjamäki posted a comment on discussion Development
It's still being processed. If we will have trouble to keep up with open PRs I think we can launch more runner VMs. It might be low with 100/1000 .. I will see if it makes sense to increase these values later. At least if a runner is idle it could fill up more packages..
-
CHR modified a comment on discussion Development
Good idea 🆙 Having the user name in a column would be nice. Also, some PRs seem to be missing. Are they still being processed?
-
CHR posted a comment on discussion Development
Good idea 🆙 Having the user name in a column would be nice.
-
Daniel Marjamäki modified a comment on discussion Development
I am experimenting with a webserver that will execute the test-my-pr script on PRs. I want more or less that it will provide daca@home feedback directly when somebody works on a PR. http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/ It is only executed on open non-draft PRs that have a successful CI. It will execute on 1000 packages if the PR modifies tokenizer or valueflow. Otherwise it will execute on 100 packages. When I started it , it would count packages even if they did not have C/C++...
-
Daniel Marjamäki posted a comment on discussion Development
I am experimenting with a webserver that will execute the test-my-pr script on PRs: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/ It will execute on 1000 packages if the PR modifies tokenizer or valueflow. Otherwise it will execute on 100 packages. When I started it , it would count packages even if they did not have C/C++ code that is fixed now.. AI-generated verdicts will be provided for a random subset of the warnings (up to 20 or so). Those should be taken with a grain of salt for...
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15089
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15088
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15087
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15086
-
CJ Wood posted a comment on discussion General Discussion
I see a false positive running cppcheck 2.22.0 against the following code. Note the parameter cannot be declared as reference to const because its job is to match both const and mutable references, and return a reference to a member which retains the const-ness of the first argument (similar to the 'deduce this' pattern). The static asserts demonstrate the intended use cases. Note also that the false positive goes away if the concept is inlined as a template requires clause on the function itself...
-
CJ Wood posted a comment on discussion General Discussion
I see a false positive running cppcheck 2.22.0 against the following code. Note the function itself cannot be static because it's an explicit member function (deducing this). #include <array> #include <cstddef> #include <ranges> #include <span> constexpr std::size_t GridSize{19}; class board { public: auto rows(this auto&& self) { auto* cells = self.data.data(); return std::views::iota(0zu, GridSize) | std::views::transform([cells](std::size_t row) { return std::span{cells + row * GridSize, GridSize};...
-
Dan Workman modified a comment on discussion General Discussion
We've had this issue for many releases so can't provide a version that it started Running cppcheck --std=c++20 --enable=style,warning --template=gcc repro.cpp on namespace Legacy { struct Base { int Count() const; virtual void Print() const; virtual ~Base() = default; }; struct Position : Base { }; } using namespace Legacy; namespace Modern { struct Position { int Count() const; void Print() const; }; } gives repro.cpp:21:7: warning: The struct 'Position' defines member function with name 'Count'...
-
Dan Workman posted a comment on discussion General Discussion
We've had this issue for many releases so can't provide a version that it started Running cppcheck --std=c++20 --enable=style,warning --template=gcc repro.cpp on namespace Legacy { struct Base { int Count() const; virtual void Print() const; virtual ~Base() = default; }; struct Position : Base { }; } using namespace Legacy; namespace Modern { struct Position { int Count() const; void Print() const; }; } gives repro.cpp:21:7: warning: The struct 'Position' defines member function with name 'Count'...
-
CHR posted a comment on discussion General Discussion
Reduced: struct S { bool f() const; int g() const; int x, y; }; bool S::f() const { const bool b = x ? g() < 0 : 0 > y; return b; }
-
Dan Workman modified a comment on discussion General Discussion
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first, int last) { for (const auto&...
-
Dan Workman modified a comment on discussion General Discussion
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first, int last) { for (const auto&...
-
Dan Workman modified a comment on discussion General Discussion
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc --error-exitcode=2 repro.cpp on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first,...
-
Dan Workman posted a comment on discussion General Discussion
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc --error-exitcode=2 repro.cpp on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first,...
-
lamoda modified a comment on discussion General Discussion
i got this error and point to first { open braces when i use this code in my sources cppcheck run this check from myproject.cppcheck but i have no any error when i check this file or dir with my sources
-
lamoda modified a comment on discussion General Discussion
i got this error and point to first { open braces when i use this code in my sources cppcheck run this check from myproject.cppcheck but i have no any error when i just this file
-
lamoda posted a comment on discussion General Discussion
i got this error and point to { open braces when i use this code in my sources cppcheck run this check from myproject.cppcheck but i have no any error when i just this file
-
Penguin posted a comment on discussion General Discussion
Hello, I found a preprocessing cache issue and have prepared a fix and regression test locally. Could a team member please create a Trac ticket so I can reference it in a pull request? Issue With --cppcheck-build-dir, unchanged input can be analyzed again on the immediate second run because the preprocessing hash depends on header load order. I reproduced this on commit fa6c1f1327057cb8ad4764df236daf6d3c70e359, using Windows x64 and an MSVC 2022 Debug build. Minimal reproduction Create these three...
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15076
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15075
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/14677
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15074
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15073
-
CHR posted a comment on discussion General Discussion
Looks like a special case of https://trac.cppcheck.net/ticket/1606
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/9921 and others.
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/2853
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/10201
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule arrayIndexOutOfBounds. Cppcheck misses an out-of-bounds write when the array is accessed through a pointer alias. int a[2]; void f() { int *p = a; p[2] = 0; } Actual result Cppcheck does not report arrayIndexOutOfBounds. Replacing p[2] = 0 with a[2] = 0 produces the warning. Expected result Cppcheck should report the out-of-bounds write through the alias. Verification The issue was reproduced with: cppcheck --output-format=xmlv2 --enable=all array_alias.cpp...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule arrayIndexOutOfBounds. Cppcheck misses an out-of-bounds write when the array expression is written as the address of its first element. int a[2]; void f() { (&a[0])[2] = 0; } Actual result Cppcheck does not report arrayIndexOutOfBounds. Replacing (&a[0])[2] = 0 with a[2] = 0 produces the warning. The form ((int *)a)[2] = 0 is also missed. Expected result Cppcheck should report the out-of-bounds write in these equivalent subscript forms. Verification...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule resourceLeak. Cppcheck misses the resource leak when the null check uses a local alias of the file pointer. #include <cstdio> int f() { const FILE *a = fopen("input.txt", "r"); const FILE *b = a; if (!b) return 0; return 0; } Actual result Cppcheck does not report resourceLeak. Removing b and changing the condition to if (!a) produces the warning. Expected result Cppcheck should report the missing fclose in both forms. Verification The issue was reproduced...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule memleak. Cppcheck misses the leak when the allocated buffer is accessed through a pointer-to-pointer alias. #include <stdlib.h> int f(void) { int result = 0; char *a = malloc(10); char **b = &a; if (*b) { (*b)[0] = 0; result = (*b)[0]; } return result; } Actual result Cppcheck does not report memleak. Removing b and replacing each *b access with a produces the warning. Expected result Cppcheck should report the missing free in both forms. Verification...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule invalidContainer. Cppcheck misses the use of an invalidated iterator when the vector is accessed through a reference alias. #include <vector> void f() { std::vector<int> items{1, 2, 3}; std::vector<int> &values = items; auto iter = values.begin(); values.erase(iter); ++iter; } Actual result Cppcheck does not report invalidContainer. Removing the reference declaration and replacing values with items produces the warning. Expected result Cppcheck should...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule invalidContainer. Cppcheck misses the use of an invalidated vector iterator when the increment is written as an explicit operator call. #include <vector> void f() { std::vector<int> items{1, 2, 3}; std::vector<int>::iterator iter; for (iter = items.begin(); iter != items.end(); iter.operator++()) { if (*iter == 2) items.erase(iter); } } Actual result Cppcheck does not report invalidContainer. Replacing iter.operator++() with ++iter produces the warning....
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule autoVariables. Cppcheck misses an escaping local address when it passes through a pointer temporary. void f(int **out) { int local = 1; int *temporary = &local; *out = temporary; } Actual result Cppcheck does not report autoVariables. Replacing the last two statements with *out = &local; produces the warning. Expected result Cppcheck should report that the address of the local variable is assigned through the output parameter in both forms. Verification...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule arrayIndexOutOfBounds. Cppcheck misses an out-of-bounds write when array indexing is written as pointer arithmetic. int a[2]; void f() { *(a + 2) = 0; } Actual result Cppcheck does not report arrayIndexOutOfBounds. Replacing *(a + 2) = 0 with a[2] = 0 produces the warning. Expected result Cppcheck should report the out-of-bounds write in both forms. Verification The issue was reproduced with: cppcheck --output-format=xmlv2 --enable=all array_pointer.cpp...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative regarding the rule AssignmentAddressToInteger. Cppcheck misses the pointer-to-integer conversion when it is written as a compound assignment. int f(int *p) { int a = 0; a += p; return a + 4; } Actual result Cppcheck does not report AssignmentAddressToInteger. Replacing a += p with a = a + p produces the warning. Expected result Cppcheck should also report the pointer-to-integer conversion in the compound assignment. Verification The issue was reproduced with: cppcheck...
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15070
-
tsteven posted a comment on discussion General Discussion
The syntaxError comes from Tokenizer::findGarbageCode. (line numbers from eb4b6526b3502ee779a74019f814d45d890427ba) Breakpoint 1.1, Tokenizer::syntaxError (this=0x7fffffffc550, tok=0x555556240920, code="") at /home/tsteven4/work/cppcheck/lib/tokenize.cpp:8441 8441 { (gdb) bt #0 Tokenizer::syntaxError (this=0x7fffffffc550, tok=0x555556240920, code="") at /home/tsteven4/work/cppcheck/lib/tokenize.cpp:8441 #1 0x00005555556f183f in Tokenizer::findGarbageCode (this=0x7fffffffc550) at /home/tsteven4/work/cppcheck/lib/tokenize.cpp:9113...
-
tsteven posted a comment on discussion General Discussion
cppcheck reports a false positive syntaxError on c++20 bitfields that contain both a size and a brace initializer, which were allowed in c++20. A test case below includes sizes from more complex integral constant expressions, but handling the simple case "int m5:5{55};" would allow the most common usage to proceed in cppcheck. I reproduced this with 2.19.0 on ubuntu 26.04, but it also fails with main@eb4b6526b3502ee779a74019f814d45d890427ba cppcheck --enable=all --std=c++20 test.cc Checking test.cc...
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15061
-
CHR posted a comment on discussion General Discussion
Added here: https://trac.cppcheck.net/ticket/11563
-
CHR posted a comment on discussion General Discussion
The false negative with visible function definition looks similar to https://trac.cppcheck.net/ticket/14804
-
CHR posted a comment on discussion General Discussion
Added here: https://trac.cppcheck.net/ticket/15058
-
CHR posted a comment on discussion General Discussion
I don't get a syntaxError with latest head.
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15059
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 when a boolean comparison result is multiplied into the divisor. Affected tool Cppcheck 2.21.0 Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer int divide_by_boolean_product(int x, int y) { int divisor = (x < 0) * y; return 1 / divisor; } Reproduction command cppcheck --version cppcheck --enable=warning --std=c11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-boolean-product.c...
-
lamoda posted a comment on discussion General Discussion
template <typename T> concept TQueue = requires(const T & t) { { t.empty() } -> std::same_as<bool>; }; it seems all ok was till version 2.20.0
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15058
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15057
-
Nikita Leontiev posted a comment on discussion General Discussion
Ticket is marked as fixed, but initial case is not fixed in cppcheck 2.22.0.
-
Nikita Leontiev posted a comment on discussion General Discussion
cppcheck 2.22.0 generates unusedPrivateFunction and unusedFunction for the following code: #define CASE(msg, handler) \ case msg: CASE_##msg((handler)) #define MSG1 1 #define CASE_MSG1(handler) handler() class Object { private: int m_num; public: Object() : m_num(0) {} static void msg_proc(int msg, void *context) { switch (msg) { CASE(MSG1, reinterpret_cast<Object*>(context)->msg1_handler); } } private: void msg1_handler() { m_num = 1; } }; int main() { Object obj; Object::msg_proc(MSG1, reinterpret_cast<void*>(&obj));...
-
Nikita Leontiev posted a comment on discussion General Discussion
cppcheck 2.22.0 generates functionStatic for the following code: #define CASE(index, method) \ case index: return CASE_##method((method)) #define CASE_method1(method) method() class Object { private: int m_num; public: Object() : m_num(0) {} void call(int index) { switch (index) { CASE(1, method1); } } private: void method1() { m_num = 1; } }; int main() { Object().call(1); return 0; } test\main.cpp:11:7: style: The member function 'Object::call' can be static. [functionStatic] void call(int index)...
-
Nikita Leontiev posted a comment on discussion General Discussion
cppcheck 2.22.0 generates noDestructor for the following code: #include <windows.h> class NonCopyable { protected: NonCopyable() {} private: NonCopyable(const NonCopyable&); NonCopyable& operator=(const NonCopyable&); }; class Brush : public NonCopyable { private: HBRUSH m_brush; public: explicit Brush(HBRUSH brush) : m_brush(brush) {} ~Brush() { if (m_brush) DeleteObject(m_brush); } }; class GDI : public NonCopyable { private: Brush m_brush; public: GDI() : m_brush(CreateSolidBrush(RGB(0, 0, 0)))...
-
cppcheck released /cppcheck/2.22/README.md
-
cppcheck released /cppcheck/2.22/cppcheck-2.22.0.zip
-
cppcheck released /cppcheck/2.22/cppcheck-2.22.0.tar.gz
-
cppcheck released /cppcheck/2.22/cppcheck-2.22.0.tar.bz2
-
Daniel Marjamäki created a blog post
Cppcheck 2.22.0
-
cppcheck released /cppcheck/2.22/cppcheck-2.22.0-x64-Setup.msi
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15052
-
CHR posted a comment on discussion General Discussion
Example added here: https://trac.cppcheck.net/ticket/14239
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15051
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/10
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/14239
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when destruction of a temporary object changes a global value to zero before a division. Affected tool Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer int global; struct Value { Value() { global = 1; } ~Value() { global = 0; } }; int test() { Value{}; return 1 / global; } Reproduction command cppcheck --version cppcheck --enable=warning...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a constant argument makes a division inside a function-template instantiation divide by zero. Affected tool Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer bool unknown(); template <class T> void divide(T value) { if (unknown()) value = 1 / (value - 5); } void test() { divide<int>(5); } Reproduction command cppcheck --version...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 when a switch case constrains the divisor to zero. Affected tool Cppcheck 2.21.0 Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer int divide_in_zero_case(int value) { switch (value) { case 0: return 1 / value; default: return 0; } } Reproduction command cppcheck --version cppcheck --enable=warning --std=c11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-switch-case.c...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a helper writes zero through a pointer before the pointed-to value is used as a divisor. Affected tool Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer void set_zero(int *value) { *value = 0; } int test() { int value; set_zero(&value); return 1 / value; } Reproduction command cppcheck --version cppcheck --enable=warning --std=c++17...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 when two branch constraints establish that an expression used as a divisor is zero. Affected tool Cppcheck 2.21.0 Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer int divide_after_two_constraints(int x, int y) { if (y != 0) return 0; if (x + y != 0) return 0; return y / (x + y); } Reproduction command cppcheck --version cppcheck --enable=warning --std=c++11 --checkers-report=checkers.txt --template='{file}:{line}:{column}:...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when memset zeroes a local integer before it is used as a divisor. Affected tool Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer #include <cstring> int test() { int value = 1; std::memset(&value, 0, sizeof(value)); return 1 / value; } Reproduction command cppcheck --version cppcheck --enable=warning --std=c++17 --checkers-report=checkers.txt...
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 when a logical expression selects a zero-valued ternary branch. Affected tool Cppcheck 2.21.0 Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer int divide_after_logical_ternary(bool left, bool right) { int divisor = (left || right) ? 0 : 1; return 1 / divisor; } Reproduction command cppcheck --version cppcheck --enable=warning --std=c++11 --checkers-report=checkers.txt --template='{file}:{line}:{column}:...
-
CHR posted a comment on discussion General Discussion
We don't warn about the expression return true || divisor;, which is arguably dubious, but may be intentional, similar to if (false) etc. So we won't report the induced unreadVariable either.
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15037
-
CHR posted a comment on discussion General Discussion
There is a deliberate bailout to allow "trivial" initialization.
-
CHR posted a comment on discussion General Discussion
See https://trac.cppcheck.net/ticket/14405
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15036
-
CHR posted a comment on discussion General Discussion
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15035
-
Rodri posted a comment on discussion General Discussion
Hi, I found a false negative in Cppcheck 2.21.0 when a local variable is used only on the unevaluated right-hand side of a short-circuit expression. Affected tool Cppcheck 2.21.0 Affected checker unreadVariable Minimal reproducer int test() { int source = 0; int divisor = source; return true || divisor; } Reproduction command cppcheck --version cppcheck --enable=all --inconclusive --check-level=exhaustive --std=c++17 --output-format=xmlv2 mutant-cppcheck-unreadvariable-fn-short-circuit-rhs.cpp Current...
-
Rodri posted a comment on discussion General Discussion
Cppcheck 2.21.0 misses a scalar store that is never read before a switch completes. The minimal trigger contains no loop or continue. Affected tool and checker Cppcheck 2.21.0, unreadVariable / CheckUnusedVar liveness handling. Minimal reproducer void test(int input) { int value; value = 0; switch (input) { case 0: break; default: break; } } Reproduction command cppcheck --enable=all --inconclusive --check-level=exhaustive --std=c++17 \ --template='{file}:{line}:{column}: [{id}] {message}' \ mutant-cppcheck-unreadvariable-fn-switch-dead-store.cpp...
-
Rodri posted a comment on discussion General Discussion
Cppcheck 2.21.0 misses an initialization whose explicit floating conversion is overwritten before the initialized value is read. Affected tool and checker Cppcheck 2.21.0, redundantInitialization. Minimal reproducer void initialize(double &); float test() { double input; initialize(input); float value = (float)input; value = 3.14f; return value; } Reproduction command cppcheck --enable=all --inconclusive --check-level=exhaustive --std=c++17 \ --template='{file}:{line}:{column}: [{id}] {message}'...
