Commit Graph

1011 Commits

Author SHA1 Message Date
Daniel Marjamäki 56924643be Fixed #10347 (ValueFlow: No known value set for sizeof(a[0])) 2021-07-08 18:18:44 +02:00
Armin Müller fc90598077
Typos found by running "codespell" (#3324) 2021-07-02 17:41:51 +02:00
Daniel Marjamäki 1a5449cbeb Fixed #10327 (ValueFlow; Wrong Uninit value in called function) 2021-07-01 22:08:00 +02:00
Daniel Marjamäki 2a2e071a85 Tokenizer::simplifyAttribute; Set function attribute for function pointer 2021-06-26 14:23:39 +02:00
Paul Fultz II 66956ed959
Fix 10323: Wrong known value. x!=0 does not mean that x==1 (#3308) 2021-06-26 09:16:45 +02:00
Paul Fultz II 508188df2b
Fix 10297: Regression; ValueFlow known value, sign conversion (#3307) 2021-06-26 09:16:04 +02:00
Daniel Marjamäki 769b20b426 ValueFlow: Clarify note when impossible value is assigned (#10297) 2021-06-24 17:10:06 +02:00
Daniel Marjamäki 2d08564c8a astyle formatting 2021-06-19 14:47:35 +02:00
Paul Fultz II dd178c3ad9
Fix 10314: Possible nullPointerRedundantCheck false positive (#3298) 2021-06-19 13:59:48 +02:00
Paul Fultz II f55a4563f9
Fix 10308: danglingTemporaryLifetime confused by function parameter (#3292) 2021-06-09 09:21:03 +02:00
Paul Fultz II f3a33ea330
Fix 10294: ValueFlow: Wrong <Uninit> value below loop (#3291) 2021-06-09 09:20:43 +02:00
orbitcowboy 195d413986 Running astyle [ci skip] 2021-06-05 08:53:15 +02:00
Paul Fultz II f90b05ea7c
Show lifetime kind in output (#3285) 2021-06-04 21:41:30 +02:00
Paul Fultz II 668b88d7c0
Fix 10284: False positive; valueFlowBeforeCondition does not seem to care about increment (#3287) 2021-06-04 21:40:57 +02:00
Paul Fultz II a14922ed85
Fix 10238: FP knownConditionTrueFalse std::string from const char* assumed non-empty (#3288) 2021-06-04 17:22:05 +02:00
Paul Fultz II 537fb5bcd9
Fix 10264: FP invalidContainer when address of container is passed inside struct (#3286) 2021-06-04 17:20:47 +02:00
Paul Fultz II 486e440c4a
Fix 10298: ValueFlow: Wrong known value, 'x == -1' implicit unsigned cast for rhs (#3277) 2021-06-04 17:17:41 +02:00
Paul Fultz II 95c872b1ec
Fix todo test for returning a dangling reference (#3284) 2021-06-04 17:15:39 +02:00
Paul Fultz II 548ec10824
Fix issue 10306: FP knownConditionTrueFalse with modulo result converted to bool (#3282) 2021-06-03 07:26:36 +02:00
Paul Fultz II ab50a75d8a
Fix 10289: ValueFlow; Wrong known value 'size_t - uint16_t > 0' (#3273) 2021-05-24 08:28:21 +02:00
Paul Fultz II 47a4144b47
Fix 10288: ValueFlow; False positives because of wrong known value when there is sign cast (#3268) 2021-05-23 10:20:29 +02:00
Paul Fultz II 8541e0503e
Fix 10290: false negative: container out of bounds (#3269) 2021-05-22 23:33:13 +02:00
Paul Fultz II c63aa2f2cc
Fix 10263: FP containerOutOfBounds when container is accessed via pointer (#3265) 2021-05-22 08:36:51 +02:00
Paul Fultz II 1e3ab460a3
Fix 10254: false positive: arrayIndexOutOfBounds in inline function (#3266) 2021-05-22 08:20:09 +02:00
Armin Müller c70b8793a3
Typos found by running "codespell" (#3251) 2021-05-19 11:49:19 +02:00
Paul Fultz II 4b11bb4ad3
10278: ValueFlow: Wrong known value, sign conversion (#3260) 2021-05-18 07:28:45 +02:00
Paul Fultz II eb96e4980e
Fix issue 10268: ValueFlow; Wrong value in for loop (#3257) 2021-05-15 08:39:20 +02:00
Daniel Marjamäki abb4200316 Fixed #10196 ("Unhandled char constant 'x'" with non-standard escape character) 2021-05-08 12:54:18 +02:00
Daniel Marjamäki 07c1f28035 astyle formatting 2021-05-01 07:35:03 +02:00
Paul Fultz II 31e3e4d87b
Fix issue 10086: false positive: (style) constVariable: Variable 'x' can be declared with const (#3219) 2021-04-30 17:47:08 +02:00
Daniel Marjamäki 04e9c13bc6 TemplateSimplifier; Better handling of c++17 fold expressions and c++20 concepts.
c++17 fold expressions are simplified to a __cppcheck_uninstantiated_fold__ if they are not instantiated.

c++20 concepts are skipped/removed by Cppcheck and these will be enforced by the compiler.
2021-04-20 15:40:25 +02:00
Paul Fultz II db5f00a16a
Fix issue 10214: FP: danglingTempReference doesn't account for reference lifetime extension (#3220)
* Fix issue 10214: FP: danglingTempReference doesn't account for reference lifetime extension
2021-04-19 14:20:29 +02:00
Paul Fultz II 563c9dd9cc
Fix issue 10208: FP: knownConditionTrueFalse in for loop with function that assigns by ref (#3198) 2021-04-18 21:42:27 +02:00
Paul Fultz II a772d652d8
Fix issue 9932: FP: containerOutOfBounds (#3217)
* Fix issue 9932: FP: containerOutOfBounds
2021-04-18 10:43:38 +02:00
Oliver Stöneberg 5a7e361442
run self-checks with standard set to C++11 (#3206) 2021-04-12 18:29:13 +02:00
Paul Fultz II 255f273c46
Fix issue 10088: ValueFlow: Array size, wrong known value (#3204) 2021-04-09 07:43:54 +02:00
Paul Fultz II e0f9627201
Fix issue 10226: FP: redundant condition or invalid iterator (#3195) 2021-04-06 11:04:37 +02:00
Paul Fultz II f605f71e49
Fix issue 10225: false positive: knownConditionTrueFalse (#3196) 2021-04-05 10:20:14 +02:00
Daniel Marjamäki 44f914eaee astyle formatting
ci skip
2021-04-04 18:20:32 +02:00
Paul Fultz II 182ae75290
Fix issue 10216: FP containerOutOfBounds with std::array initialized with = {} (#3190) 2021-03-31 22:07:54 +02:00
Oliver Stöneberg 9b974f1b8e
fixed Visual Studio warnings about shadowed members (#3191) 2021-03-31 22:07:20 +02:00
Paul Fultz II 5077663684
Fix issue 9979: false positive: containerOutOfBounds with conditional resize (#3136) 2021-03-30 14:02:28 +02:00
Paul Fultz II 9de976b243
Fix issue 10194: hang with followAllReferences() (#3189)
* Decrease depth faster when there is multiple returns
2021-03-30 11:22:56 +02:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
PKEuS 141d2ac215 Refactorization: Improved internal implementation of severity and certainty levels
Backported from LCppC.
2021-02-24 22:00:06 +01:00
PKEuS 6a811eec1c Refactorization: Removed unused functions 2021-02-17 22:44:03 +01:00
Daniel Marjamäki 0a71b52a87 Remove unused function 2021-02-11 19:27:36 +01:00
Daniel Marjamäki fbf63b932e astyle formatting
[ci skip]
2021-02-10 11:42:00 +01:00
Oliver Stöneberg 39c5274742
valueflow.cpp: optimized SingleValueFlowAnaylzer::isAlias() by avoidi… (#3051) 2021-02-10 08:18:21 +01:00
Paul Fultz II 0e871c178f
Fix issue 10141: Errors with ref assignment (duplicateValueTenary and knownEmptyContainer) (#3093) 2021-02-09 15:27:46 +01:00
Paul Fultz II cf8a5d9a22
Fix issue 10111: FP knownConditionTrueFalse (#3110) 2021-02-03 10:21:47 +01:00
Paul Fultz II 913dbeb8d8
Fix FP when inserting a range into a container (#3108) 2021-02-02 14:57:48 +01:00
Paul Fultz II e17d22eb87
Fix issue 10134: False positive: value is not known. Early return. (#3086) 2021-01-28 12:37:56 +01:00
IOBYTE 4e1ff86bb2
use nonneg int for varid and exprid (#3085) 2021-01-27 19:49:13 +01:00
Daniel Marjamäki 987c8a854e astyle formatting
[ci skip]
2021-01-25 22:51:50 +01:00
Paul Fultz II 0f8f207719
Remove valueFlowFwdAnalysis and update valueFlowAfterAssign to handle expressions (#3074) 2021-01-25 17:24:36 +01:00
Daniel Marjamäki 772b44d11a Fixed compiler warnings 2021-01-23 18:04:28 +01:00
Paul Fultz II c860de8565
Fix issue 8143: valueFlowCondition: before and inside while (#3045) 2021-01-23 17:52:01 +01:00
Paul Fultz II d80f2fb46f
Reapply f1cc3ad and fix performance regression (#3076) 2021-01-23 08:47:39 +01:00
orbitcowboy bb451ca289 Running astlye [ci skip] 2021-01-22 21:47:24 +01:00
Daniel Marjamäki 0fa89ff2ba Revert 14365ffc7 and f1cc3ada8, there was a performance regression 2021-01-22 10:51:46 +01:00
Daniel Marjamäki 14365ffc7c make a function static 2021-01-21 20:27:28 +01:00
Paul Fultz II f1cc3ada86
Refactor valueFlowTerminatingCondition to handle inner conditions and complex conditions (#3060) 2021-01-21 20:18:53 +01:00
Paul Fultz II d05acf3c41
Fix issue 10120: FP: containerOutOfBounds, regression (#3064) 2021-01-21 19:50:57 +01:00
Paul Fultz II 8b26ecbcdd
Extend ProgramMemory to handle expressions (#3069) 2021-01-21 19:49:37 +01:00
Paul Fultz II 25ada657da
Fix issue 9030: ValueFlow: Possible value after conditional assignment in for loop (#3059) 2021-01-18 10:12:07 +01:00
Paul Fultz II b571e9fe0b
Fix issue 10106: FP: nullPointerRedundantCheck (#3044) 2021-01-13 12:36:26 +01:00
Daniel Marjamäki 1858465bca astyle formatting
[ci skip]
2021-01-12 21:28:56 +01:00
Armin Müller 0de0a954d2
Typos found by running "codespell" (#3042) 2021-01-12 20:48:25 +01:00
Paul Fultz II b1c56d33ac
Fix issue 9133: Invalid iterator; vector::push_back, functions (#3008) 2021-01-11 18:47:38 +01:00
Paul Fultz II 678ee00fe9
Infer variables from conditions in valueFlowSubfunction (#3037) 2021-01-11 08:00:13 +01:00
Paul Fultz II a3617fe573
Fix issue 10102: False positive: knownConditionTrueFalse in for loop (#3038) 2021-01-11 07:56:16 +01:00
Daniel Marjamäki 707f1f2fbe ValueFlow: Fixed isEqual 2021-01-10 16:52:11 +01:00
Daniel Marjamäki 98c7c0af96 Fixed GCC compiler warnings 2021-01-10 15:27:42 +01:00
Daniel Marjamäki f493ce16b3 astyle formatting
[ci skip]
2021-01-10 14:46:19 +01:00
Paul Fultz II bc3f5554a4
Fix issue 8871: improve check: mismatching container size conditions (#2988) 2021-01-10 13:30:00 +01:00
Paul Fultz II c267d85640
Add generic valueflowBeforeCondition (#3001) 2021-01-08 22:55:04 +01:00
Oliver Stöneberg 96704c9971
fixed and enabled some more clang-tidy warnings (#3007) 2021-01-05 17:51:32 +01:00
Paul Fultz II e004731f1c
Fix issue 8650: ValueFlow: Track if pointer is created by '&' operator (#3011) 2021-01-05 16:56:38 +01:00
Paul Fultz II f0b5668436
Fix issue 9890: ValueFlow: known value not found (variable is changed in path that returns) (#3010) 2021-01-05 16:49:08 +01:00
Oliver Stöneberg d59abfd977
fixed clang-tidy warnings (#3006)
* clang_tidy.cmake: added clang-tidy-11 to list of executables to look for

* .clang-tidy: disabled warnings we are (currently) not interested in

* fixed clang-tidy warnings
2021-01-02 23:10:27 +01:00
Rikard Falkeborn d19454b935
Refactoring: Convert ValueType to enum class (#3005) 2021-01-02 09:30:00 +01:00
shaneasd 53734a3da1
Test for return address of reference (#2991) 2020-12-28 10:50:42 +01:00
orbitcowboy 38fc6f209d Running astye [ci skip] 2020-12-26 14:02:03 +01:00
Oliver Stöneberg 00071d09f6
split "valueFlowBailoutIncompleteVar" from more generic "valueFlowBailout" (#2976) 2020-12-26 13:48:22 +01:00
Daniel Marjamäki 8fcef7ad0d astyle formatting
ci skip
2020-12-25 08:58:12 +01:00
Paul Fultz II 7861aa00cf
Refactor afterCondition handlers into to seperate classes (#2975) 2020-12-24 20:07:46 +01:00
Paul Fultz II a770342593
Fix crash in getInitListSize (#2960) 2020-12-19 12:23:19 +01:00
Daniel Marjamäki 1744cbaf66 astyle formatting
[ci skip]
2020-12-19 08:56:46 +01:00
Paul Fultz II 626dcd0eba
Fix issue 10037: False positive when passing variables to functions by address (#2957) 2020-12-19 08:29:37 +01:00
Paul Fultz II b044f9ba96
Fix issue 9996: false negative: containerOutOfBounds with std::vector::front() and c++11 braced initializer (#2958) 2020-12-18 07:14:11 +01:00
Paul Fultz II 904d52acac
Fix issue 10004: ValueFlow: pointer value, wrongly set known value (#2931) 2020-12-03 07:15:31 +01:00
IOBYTE 43ce1607c7
fix a large number of valgrind warnings in testrunner (#2920)
Co-authored-by: Robert Reif <reif@FX6840>
2020-11-24 18:21:07 +01:00
Daniel Marjamäki 5e69def679 Code cleanup; Remove unused functions 2020-11-18 20:27:51 +01:00
Paul Fultz II e8c1c792a5
Fix issue 9987: false positive: danglingTempReference with && variable and assignment (#2907) 2020-11-17 06:52:12 +01:00
Rikard Falkeborn 324e267559
getSizeOf: Handle long double (#2888) 2020-11-11 22:51:17 +01:00
Daniel Marjamäki 7182da5c8e astyle formatting 2020-11-11 09:17:54 +01:00
Paul Fultz II bd7e915c20
Add generic reverse valueflow (#2878) 2020-11-10 16:00:55 +01:00
Daniel Marjamäki 88a35d2253 Fix CodeQL warning, Multiplication result converted to larger type 2020-11-06 19:50:05 +01:00
Rikard Falkeborn d7a8e25d92
Fix #9647: Set correct enum value (#2856)
* Tokenize: Set varId for variables in enum

Set varIds in enum values. It was previously disabled in 5119ae84b8
to avoid issues with enums named the same as global variables. Take care
to only set varids to variables used to set the value of an enumerator,
not the enumerator itself. This is somewhat complicated by the fact that
at the time this happens, astOperand1(), astOperand2(), astParent() etc
are not set. The current implementation is not perfect, for example in
the code below, y will not have a varid set, but x and z will. This is
deemed sufficient for now.

            int x, y, z;
            enum E { a = f(x, y, z); };

* Fix #9647: Value of enums with variables as init values

C++ allows enum values to be set using constexprs, which cppcheck did
not handle before. To solve this, add a new pass to valueflow to update
enum values after global consts have been processed. In order to do so,
I moved all settings of enum values to valueflow. After setting the enum
values, we need another call to valueFlowNumber() to actually set users
of the enums.

There is still room for improvements, since each pass of
valueFlowGlobalConstVar() and valueFlowEnumValue() only sets variables
that are possible to set directly, and not if setting the value of a
variable allows us to set the value of another. For example

	constexpr int a = 5;
	constexpr int b = a + 5;
	enum E { X = a };
	constexpr E e = X;

Here both b and e will not have their values set, even though cppcheck
should be possible to figure out their values. That's for another PR
though.

This was tested by running test-my-pr.py with 500 packages. The only
difference was one error message in fairy-stockfish_11.1, where cppcheck
now printed the correct size of an array instead of 2147483648 which I
assume is some kind of default value. In that package, using a constexpr
when setting enum values is common, but as mentioned, there was no
change in the number of warnings.
2020-10-22 07:45:04 +02:00