I tried cppcheck 2.6.2 (and c7ef602cd6d58af2ef3d5a7ec01b53dded03cc05) on our C codebase and got these two problems. Perhaps someone with access to be bug tracker can add them there?
#include <stdint.h> int func(void) { static uint32_t v; if (++v == 0) { ++v; return 1; } return 0; }
It gives the following output:
test.c:7:13: style: Condition '++v==0' is always false [knownConditionTrueFalse] if (++v == 0) { ^
This is perhaps a variant of #10248 ?
A function converting one enum to another in a creative way fails with a broken AST error:
typedef enum { A, B, C } enum1_t; typedef enum { D, E, F } enum2_t; enum2_t func1(enum1_t v) { return (enum2_t[]) { [A] = D, [B] = E, [C] = F }[v]; } enum2_t func2(enum1_t v) { enum2_t ret; ret = (enum2_t[]) { [A] = D, [B] = E, [C] = F }[v]; return ret; }
func1 works fine, func2 fails with:
test2.c:25:9: error: Syntax Error: AST broken, binary operator '=' doesn't have two operands. [internalAstError] ret = (enum2_t[]) { ^
In the first case, you are relying on unsigned overflow, right? The second example should be covered by https://trac.cppcheck.net/ticket/10177
Yes, its with unsigned overflow.
I missed 10177 when I searched for it, sorry about that.
No worries. Here is a ticket for the first issue: https://trac.cppcheck.net/ticket/10616
Log in to post a comment.
I tried cppcheck 2.6.2 (and c7ef602cd6d58af2ef3d5a7ec01b53dded03cc05) on our C codebase and got these two problems. Perhaps someone with access to be bug tracker can add them there?
It gives the following output:
This is perhaps a variant of #10248 ?
A function converting one enum to another in a creative way fails with a broken AST error:
func1 works fine, func2 fails with:
In the first case, you are relying on unsigned overflow, right?
The second example should be covered by https://trac.cppcheck.net/ticket/10177
Yes, its with unsigned overflow.
I missed 10177 when I searched for it, sorry about that.
No worries. Here is a ticket for the first issue: https://trac.cppcheck.net/ticket/10616