cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

do not set values if there is no expression

Open firewave opened this issue 11 months ago • 2 comments

firewave avatar Feb 07 '25 23:02 firewave

All tests still pass with the early returns added.

Example output:

TestLeakAutoVar::doublefree9
ExprIdToken - no tok
setValue - no expr - 0@1
setValue - no expr - 0@1
ExprIdToken - no tok
setValue - no expr - 1@2
setValue - no expr - 1@2
setValue - no expr - 1
setValue - no expr - 0

Looks like this is related to unnamed parameters.

@pfultz2 please have a look.

firewave avatar Feb 07 '25 23:02 firewave

Happens with unnamed parameters when a function body exists:

void cb(int) {}

void func()
{
    cb(0);
}
ExprIdToken - no tok
setValue - no expr - 0@1
ExprIdToken - no tok
solveExprValue - no expr
setValue - no expr - 0@1
ExprIdToken - no tok
solveExprValue - no expr


##file scratch_3.cpp
1: void cb ( int ) { }
2:
3: void func ( )
4: {
5: cb (@exprUNIQUE 0 ) ;
6: }



##Value flow
File scratch_3.cpp
Line 5
  0 always 0

Naming the parameter fixes it:

##file scratch_3.cpp
1: void cb ( int i@var1 ) { }
2:
3: void func ( )
4: {
5: cb (@exprUNIQUE 0 ) ;
6: }



##Value flow
File scratch_3.cpp
Line 5
  0 always 0

firewave avatar Feb 08 '25 13:02 firewave

The MultiValueFlowAnalyzer happens in TestAutoVariables::testinvaliddealloc (among others). I assume that should not get such data so it possibly needs to be addressed earlier in the code.

firewave avatar Aug 08 '25 13:08 firewave

spontanously this sounds good to me. what is the motivation? is there speedup or change of results or simpler code?

I cannot remember how I came across this but I assume it was in the context of some of the other drafts PRs where I try to get rid of unnecessary calls.

Depending on the code this might have performance implications as less values are being generated.

firewave avatar Aug 25 '25 11:08 firewave

I tested it with #7800 and there were no differences in the output.

firewave avatar Sep 08 '25 08:09 firewave