Commit Graph

427 Commits

Author SHA1 Message Date
Paul Fultz II 243fa66bd3
Fix 12031: False positive: uninitialized variable (#5637) 2023-12-10 19:42:35 +01:00
chrchr-github 77d8eaa2a1
Fix #12206 FN constParameterPointer with unknown const member (#5737) 2023-12-07 19:24:51 +01:00
Daniel Marjamäki 780b742568
Fix #12165 (simplifyTypedef: the "enum" token is not inserted) (#5641) 2023-11-09 07:48:33 +01:00
Paul Fultz II 18373bc64b
Fix 12116: FP negativeContainerIndex with redundant assignment (regression) (#5602) 2023-10-29 00:11:03 +02:00
Oliver Stöneberg ebb877adcc
gui/platforms.h: renamed `Platform` to `PlatformData` / Platform: removed unnecessary `cppcheck` namespace (#5545) 2023-10-13 16:02:04 +02:00
Oliver Stöneberg 06b5ef1e4d
cleaned up includes based on include-what-you-use (#5532) 2023-10-09 10:07:20 +02:00
Oliver Stöneberg 960e8bb4ea
testrunner: got rid of some redundant preprocessing code / added some missing asserts (#5521)
This consolidates the stray invocations of preprocessing.
2023-10-08 11:29:52 +02:00
moui0 eb076d877b
Improve testcases for unsigned char platforms (#5524)
I got error messages while building `cppcheck 2.12.0` for RISC-V Arch
Linux:
```
Testing Complete
Number of tests: 4420
Number of todos: 331
Tests failed: 2

/usr/src/debug/cppcheck/cppcheck/test/testcondition.cpp:4501(TestCondition::alwaysTrue): Assertion failed. 
Expected: 
[test.cpp:6]: (style) Condition 'o[1]=='\0'' is always false\n

Actual: 
[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\0'' is always false\n

_____
/usr/src/debug/cppcheck/cppcheck/test/testcondition.cpp:5014(TestCondition::alwaysTrueContainer): Assertion failed. 
Expected: 
[test.cpp:5]: (style) Condition 'buffer.back()=='\0'' is always false\n

Actual: 
[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\0'' is always false\n
```

I found out the reason is that the testcases were designed for
x86/x86_64 or other `signed char` platforms (i.e. default character type
is `signed char` ), whereareas RISC-V is an `unsigned char` platform,
which causes different behavior in
`lib/valueflow.cpp:valueFlowImpossibleValues`. I'm not sure whether this
error leads from a functional bug, so if you have a better approach to
fix it, please let me know.

Maybe you could reproduce this error on x86_64 platform by setting
`defaultSign = 'u';` in `Platform::set(Type t)`.
2023-10-07 23:04:57 +02:00
chrchr-github 903eccb336
Fix #12039 FP knownConditionTrueFalse (#5513) 2023-10-06 09:53:24 +02:00
Oliver Stöneberg 3979ade9ea
got rid of test-only `Library` functions / avoid some more direct modifications of library data structures in test (#5468) 2023-09-25 13:37:24 +02:00
Oliver Stöneberg 64cd09ab62
fixed #11917 (Default to `native` platform in Windows builds) (#5428) 2023-09-11 11:08:23 +02:00
chrchr-github 394996581e
Fix FP incorrectCharBooleanError with known condition (#5365) 2023-08-24 10:36:01 +02:00
Paul Fultz II 2adaafd20e
Fix 11887: FP knownPointerToBool with const_cast (#5357) 2023-08-23 01:07:49 +02:00
Paul Fultz II 03b952d5eb
Fix 11579: false negative: knownConditionTrueFalse with non-bool as bool parameter (#5349)
This adds a new checker to check for pointer to bool conversions that
are always known. I removed the previous knownConditionTrueFalse checks
since this was too noisy.
2023-08-20 22:32:41 +02:00
Oliver Stöneberg bfb50ca9d8
removed unnecessary `Settings` parameter from `Check::runChecks()` and made `Tokenizer` a reference (#5308)
There was no need for the `Tokenizer` parameter to be a pointer as it
could never be `nullptr` and was also dereferenced without checking
first.

As a reference to the `Settings` was already available via the
`Tokenizer` there was no need to pass it separately. In the production
code there will only be one instance of it but in the tests we could
have accidentally passed a different one.
2023-08-18 12:03:50 +02:00
chrchr-github 827e87afe7
Fix #11579 FN knownConditionTrueFalse with non-bool as bool parameter / #9450 string literal to bool conversion in function call (#5338) 2023-08-18 10:32:52 +02:00
Paul Fultz II 48c91abba6
Fix issue 11867: Assert failure in valueFlowContainerSize() (#5317) 2023-08-13 22:31:38 +02:00
Anton Lindqvist b9cc138e57
Fix FP badBitmaskCheck in nested binary expressions (#5316)
If one operand is another binary expression, recursively ensure that no
nested operands are expanded macros.
2023-08-11 23:06:24 +02:00
Paul Fultz II 24479c60f9
Fix 11850: false negative: knownConditionTrueFalse with std::string::empty() after modification (#5307) 2023-08-09 20:33:44 +02:00
Oliver Stöneberg 2502897265
avoid some redundant and unused settings in tests among other cleanups / added and used `WARN_UNUSED` attribute (#5284) 2023-08-09 12:43:55 +02:00
Oliver Stöneberg 45de338f1b
cleaned up includes based on include-what-you-use / iwyu.yml: updated to yet another distro to get the latest version and updated the Chaotic-AUR key (#5267)
This is a mess. The version is AUR is still outdated and also doesn't
install anymore. Fedora 38 carries the latest version of it so use that
now. Keep the old steps in case we need to switch again in the future.
2023-08-02 10:36:17 +02:00
Anton Lindqvist 4ebb8eaf0c
Ignore zero valued enum entries from badBitmaskCheck (#5195)
Usage of zero valued enum entries can be used for documenting purposes
and should be ignored just like zeroes expanded from macros.
2023-06-26 10:43:20 +02:00
chrchr-github 6c750d9ae9
Fix #11789 FP knownConditionTrueFalse with std::vector::size() (#5184)
There is special handling for `size_t` in
`ValueType::fromLibraryType()`, which gets preempted if it is also
configured as a podtype.
2023-06-23 20:31:25 +02:00
Oliver Stöneberg 25183ff484
testrunner: more `SettingsBuilder` usage and `const` cleanups (#5026) 2023-05-02 15:54:19 +02:00
Oliver Stöneberg 2935c855c3
reduced usage of mutable `Settings` objects in tests (#4798) 2023-05-02 11:48:24 +02:00
chrchr-github 2b92351b49
Fix #11679 FP knownArgument with known return value (#5007)
* Fix #11679 FP knownArgument with known return value

* Add test for #11051
2023-04-28 08:27:48 +02:00
Oliver Stöneberg ad464c4feb
Preprocessor: relaxed dependency on `Suppressions` (#4983)
* Preprocessor: cleaned up `missingInclude()`

* Preprocessor: relaxed dependency on `Suppressions` / adjusted `TestPreProcessor::inline_suppression_for_missing_include()` which was not testing production behavior

* test/cli/test-other.py: added test for `missingInclude` and `missingIncludeSystem` inline suppressions

* fixed `constParameterReference` selfcheck warning
2023-04-21 10:14:34 +02:00
orbitcowboy b2263d9475 #8499 Added regression test: (style) Condition 'i==0||i==1' is always true (for loop index) 2023-03-17 19:06:17 +01:00
Paul Fultz II 61e8b84578
Fix 11610: false negative: knownConditionTrueFalse with address of variable (#4883) 2023-03-12 19:57:11 +01:00
Oliver Stöneberg 901b2ab838
Preprocessor: provide suppressions separately from settings (#4878) 2023-03-09 20:15:53 +01:00
Oliver Stöneberg 50eb0641b9
iwyu.yml: added `clang-include-cleaner` job / cleaned up includes based on `include-what-you-use` (#4844) 2023-03-04 08:53:19 +01:00
Oliver Stöneberg 5af6ca6637
made `Platform` a member of `Settings` instead of inheriting from it / cleanups (#4791) 2023-03-03 18:36:27 +01:00
Oliver Stöneberg bd1ae69b00
cleaned up includes based on `include-what-you-use` (#4599) 2023-03-02 21:50:14 +01:00
Oliver Stöneberg 8f5f06add7
some `Tokenizer` construction and related other cleanups (#4799) 2023-03-02 21:48:14 +01:00
chrchr-github 491299048b
Amend fix for #11449 Function call not recognized (#4838) 2023-03-02 21:45:15 +01:00
Oliver Stöneberg 3ec4da0f8a
improved library loading in tests (#4806) 2023-03-02 21:10:51 +01:00
Paul Fultz II 346ecdb53a
Improve valueflow after pushing to container (#4803) 2023-02-23 18:05:31 +01:00
chrchr-github ff0eee4d77
Fix #11558 FP knownConditionTrueFalse when checking for zero character (#4794)
* Fix #11558 FP knownConditionTrueFalse when checking for zero characte

* Fix test

* Set impossible value only for non-Boolean conditions, rename

* Fix condition
2023-02-18 17:35:12 +01:00
Oliver Stöneberg 132a5a31cf
improved setting of platform in tests / also improved platform tests (#4787)
* fixture.h: added TODO

* TestPlatform: improved tests for built-in platforms

* TestPlatform: changed tests to TODO asserts

* testfilelister.cpp: added TODO

* fixture.h: added `PLATFORM` macro to load platform / use `PLATFORM` in tests

* platform.h: corrected capitalization in `Platform::platformString(PlatformType)` and bail on unknown type

* fixture.h: fixed `readability-redundant-string-cstr` clang-tidy warning

* testplatform.cpp: fixed `functionConst` selfcheck warnings
2023-02-11 10:44:56 +01:00
Oliver Stöneberg 7c7ccdf7c0
Check: disallow more than one instance per check (#4749) 2023-01-29 17:23:03 +01:00
Daniel Marjamäki 464fbe8d53 Update copyright year 2023-01-28 10:16:34 +01:00
Oliver Stöneberg 1d3955bd92
renamed some files in the `test` folder (#4705) 2023-01-27 08:18:32 +01:00
chrchr-github b12aebc817
Fix #9353 FN (style) Condition '...' is always true, add test for #10508 (#4731) 2023-01-26 22:03:12 +01:00
chrchr-github 4ebdf5fae1
Fix #11478 FP identicalConditionAfterEarlyExit when passing *this (#4684) 2023-01-07 22:10:07 +01:00
Paul Fultz II 9da574f4a0
Fix 11227: ValueFlow: Known value not set in condition for ternary operator (#4653)
* Evaluate args before function call

* Fix tests

* Format

* Add test for 11227

* Format

* Fix known condition
2022-12-18 22:07:43 +01:00
Paul Fultz II 9c55b933c1
Partial fix for 11303: False negative: knownConditionTrueFalse using container .back() (#4633)
* Partial fix for 11303: False negative: knownConditionTrueFalse using container .back()

* Format

* Fix error message
2022-12-15 18:35:19 +01:00
chrchr-github 553b579f8d
Fix #11434 FP knownConditionTrueFalse with loop over bool array (#4646)
* Fix #11434 FP knownConditionTrueFalse with loop over bool array

* Simplify
2022-12-15 14:31:02 +01:00
Paul Fultz II c150317f02
Fix 11384: FP knownConditionTrueFalse when variable is modified in return statement (#4625)
* Fix 11384: FP knownConditionTrueFalse when variable is modified in return statement

* Format
2022-12-09 07:15:15 +01:00
chrchr-github 04b7c0c200
Fix #11404 FP knownConditionTrueFalse with iterator (#4619)
* Fix wrong value set in valueFlowSameExpressions()

* Fix  #11404 FP knownConditionTrueFalse with iterator
2022-12-08 10:40:55 +01:00
chrchr-github 3b5601dbea
Add tests for #9327, #10597 (#4566)
* Add test for #9327

* Add test for #10597
2022-10-25 19:41:48 +02:00