Commit Graph

1128 Commits

Author SHA1 Message Date
Daniel Marjamäki da6e0308c5 Fixed #9195 (False positive: shadowFunction when constructor is shadowed) 2020-04-20 18:02:10 +02:00
Daniel Marjamäki 54978847c5 Fixed #8916 (FP: followVar does not seem to handle non-const method call properly) 2020-04-18 19:54:55 +02:00
Daniel Marjamäki 5376ba1701 AST: Throw validation exception if ternary operator is missing operands 2020-03-07 21:46:38 +01:00
amai2012 b795d30db6 Enable another zeroDivCond test which got fixed recently 2020-03-06 17:15:54 +01:00
Rikard Falkeborn f6e7fb4bd9
Bugfix valuetype for some integer constants (#2545) 2020-02-19 07:51:39 +01:00
Daniel Marjamäki 320cb9008f minor tweaks of knownConditionTrueFalse 2020-02-15 20:21:13 +01:00
Rikard Falkeborn b1c6f2946a
Fix redundant FP assignment with unsigned zero (#2521)
* Refactor isNullOperand out of FwdAnalysis

* Improve isNullOperand

* Fix redundantAssignment FP with unsigned zero

* isNullValue check number

* Enhance isNullOperand to handle c++ casts

Also handle cast of NULL.
2020-02-09 11:16:08 +01:00
Daniel Marjamäki e78775fac3 astyle formatting
[ci skip]
2020-01-10 11:31:12 +01:00
Rikard Falkeborn 9afeef01c6 Improve duplicateExpressionTernary (#2484)
Test both the cases where sizeof(int) == sizeof(long) and when they are
different to improve testing.
2020-01-10 10:02:50 +01:00
Ken-Patrick Lehrmann eca7ee9260 9356: Prevent false positive when passing non-const reference to member constructor (#2370)
* Add cases for 9356

* 9356: Prevent false positive when passing non-const reference to member constructor

This workarounds false positives 'Parameter  can be declared with const [constParameter]'
when said parameter is used in constructor call. It assume the
constructor call might change the parameter (without any checks.
The drawback is that we have false negative, in cases where we could
check the constructor actually takes a const reference, or a copied by
value parameter.

* Add todo comment in isVariableMutableInInitializer
2020-01-04 11:36:45 +01:00
Daniel Marjamäki 235ef0a01e Fixed #9420 (False positive - redundantInitialization) 2019-12-18 19:39:23 +01:00
Daniel Marjamäki bcfc5924fa Fixed #9532 (False positive: Out of bounds access in expression 'v[0]' because 'v' is empty.) 2019-12-14 19:04:19 +01:00
Paul Fultz II 06752d75a5 Fix issue 9485: knownConditionTrueFalse false positive with integer constants (#2447)
* Fix issue 9485: knownConditionTrueFalse false positive with integer constants

* Formatting
2019-12-14 09:15:00 +01:00
Dmitry-Me 064795a705 Remove duplicate test
This partially reverts commit 047418dda1
2019-12-11 19:17:59 +03:00
amai2012 f5df06a143 Run astyle [ci skip] 2019-12-08 11:22:19 +01:00
Dmitry-Me 047418dda1 Improve test coverage for redundant bitwise operations 2019-12-06 19:14:03 +03:00
Paul Fultz II ed1acc319d Fixx issue 9355: FP constParameter when returning non-const reference to struct member (#2373) 2019-11-18 06:39:50 +01:00
Rikard Falkeborn 38dea4719b Fix #9166 (print proper types in invalidCast message) (#2347)
* Fix #9166 (print proper types in invalidCast message)

* Use ValueType->str()

* astyle

* Set default sign to avoid issues on different platforms
2019-11-11 07:17:50 +01:00
Dmitry-Me 0b97f37736 Improve test coverage 2019-11-01 18:41:10 +03:00
Daniel Marjamäki 68ea60d207 Try to make Travis happy 2019-10-20 07:44:56 +02:00
Daniel Marjamäki 00fae7fb42 Fixed #9261 (Inconsistent violation report between using global enum and namespaced enum.) 2019-10-20 07:07:38 +02:00
Daniel Marjamäki 4943771e41 Fix #9262 (False positive on variable assignment when putting enum in namespace) 2019-10-19 21:41:50 +02:00
Daniel Marjamäki 99ef64459b Fixed #9344 (FP redundantAssignment related to increasing index variable for vector) 2019-10-17 18:31:05 +02:00
Steve Mokris 506a952ad2 Parse `extern "C"`, and use it to avoid FP reference warnings (#2234)
Previously, cppcheck discarded the `extern "C"` specifier.  This patch modifies cppcheck to parse each as a Scope in the symbol database, then uses that scope to avoid false positives when making recommendations about changing a function argument to be a reference (since variable references is a C++ feature, unavailable in C, and thus unavailable in `extern "C"`).
2019-10-08 17:48:09 +02:00
Oliver Stöneberg eac040a00b Various clang-tidy fixes (#2192)
* use range loops

* removed redundant string initializations

* use nullptr

* use proper boolean false

* removed unnecessary continue from end of loop

* removed unnecessary c_str() usage

* use emplace_back()

* removed redundant void arguments
2019-09-25 15:25:19 +02:00
Paul Fultz II ad8abdb0c3 Add impossible values to ValueFlow (#2186)
* Add impossible category

* Replace values

* Try to adjust known values

* Add ! for impossible values

* Add impossible with possible values

* Remove contradictions

* Add values when the branch is not dead

* Only copy possible values

* Dont bail on while loops

* Load std lib in valueflow

* Check for function calls

* Fix stl errors

* Fix incorrect impossible check

* Fix heap-after-use error

* Remove impossible values when they are lowered

* Show the bound and remove overlaps

* Infer conditions

* Dont push pointer values through dynamic_cast

* Add test for dynamic_cast issue

* Add shifttoomanybits test

* Add test for div by zero

* Add a test for issue 9315

* Dont make impossible value inconclusive

* Fix FP with shift operator

* Improve handleKnownValuesInLoop for impossible values

* Fix cppcheck warning

* Fix impossible values for ctu

* Bailout for streams

* Check equality conditions

* Fix overflows

* Add regression test for 9332

* Remove duplicate conditions

* Skip impossible values for invalid value

* Check for null

* Rename bound to range

* Formatting
2019-09-20 15:06:37 +02:00
Paul Fultz II 068b0b246c Fix issue 9352: FP constParameter and constVariable for auto& in combination with ternary ?: operator (#2173) 2019-09-13 08:33:30 +02:00
Paul Fultz II e657cf4073 Fix issue 9320: False positive knownConditionTrueFalse related to truncation (#2144) 2019-09-05 15:15:58 +02:00
Daniel Marjamäki a9fda3f488 Clarify redundantVarAssignment warnings 2019-09-04 10:55:41 +02:00
Daniel Marjamäki 4bd9d76a4c Try to make Travis happy 2019-08-25 10:24:13 +02:00
Daniel Marjamäki 82eec11898 Created redundantInitialization id 2019-08-25 09:45:39 +02:00
Daniel Marjamäki 324e5e581b Redundant assignments: Fix false positive when reassignment expression contains assembler 2019-08-24 20:15:52 +02:00
Daniel Marjamäki 7061cc334b RedundantAssignment: Don't warn for initialization with {0} 2019-08-23 08:51:16 +02:00
Paul Fultz II aaeec462e6 Re-enable valueFlowSubFunction (#2063)
* Re-enable valueFlowSubFunction

* Formatting

* Skip ternary operators in subfunctions

* Fix test with iostreams

* Fix FP with multiple parameters
2019-08-05 16:26:32 +02:00
Paul Fultz II 744a94ad5a Fix issue 9231: FP constParameter - argument passed parent ctor (#2032) 2019-07-24 20:59:58 +02:00
Paul Fultz II bb52a63c4e Add check for const variables
When a local reference is declared, this will check if that local reference can be declared as `const`.
2019-07-24 09:59:01 +02:00
Daniel Marjamäki d11d6f112e Detect shadowed arguments 2019-07-17 17:08:42 +02:00
Daniel Marjamäki cf06acae08 Fixed #5995 (False negative selfAssignment regression from 1.65) 2019-07-13 21:45:54 +02:00
Paul Fultz II 8f4cb36e1e Check for more garbage code (#1949)
* Check for garbage commas

* Find garbage dot operator
2019-07-03 08:28:24 +02:00
Scott Furry a195477470 Correct Zero/Null as pointer constant (#1938)
Building with enhanced clang warnings indicated a large number of
instances with the warning:

`warning: zero as null pointer constant`

Recommended practice in C++11 is to use `nullptr` as value for
a NULL or empty pointer value. All instances where this warning
was encountered were corrected in this commit.

Where warning was encountered in dependency code (i.e. external library)
no chnages were made. Patching will be offered upstream.
2019-06-30 21:39:22 +02:00
Daniel Marjamäki 7ceb51a952 Try to improve 'clarifyStatement' warning message 2019-06-22 08:44:41 +02:00
Daniel Marjamäki 16bed07c60 Clarify tests 2019-06-22 07:50:43 +02:00
Daniel Marjamäki 5d10b57b04 Fixed #8997 (False positive redundantAssignment when pointer is updated with +=) 2019-05-31 12:24:31 +02:00
Paul Fultz II 9838bfa79f Fix false positive in constArgument when passing struct member (#1845) 2019-05-21 10:41:16 +02:00
Daniel Marjamäki 57c6628732 Revert 'Cleaning up unsimplified templates'. This fix caused problems. 2019-05-16 21:11:04 +02:00
Daniel Marjamäki 4d9b1e6c3d Fixed #9094 (Tokenizer::createLinks2 problem with 'x%x<--a==x>x') 2019-05-11 19:11:40 +02:00
Daniel Marjamäki d58d4273f9 Cleaning up unsimplified templates 2019-05-11 13:00:03 +02:00
Daniel Marjamäki 253f2c9e9d Fixed #9043 (false positive & regression: Variable '*s' is reassigned a value before the old one has been used.) 2019-04-16 19:07:26 +02:00
Daniel Marjamäki 773d19b2d6 Fix compiler errors. After removing the -std=posix. 2019-04-12 10:41:53 +02:00
Daniel Marjamäki 3f9dd4c567 Variable scope: Fix FP for reference variable in range for loop 2019-04-02 12:59:24 +02:00