Daniel Marjamäki
70fc2a78e5
Fix Cppcheck warning
2020-11-01 18:04:13 +01:00
Daniel Marjamäki
9dc085c3ec
Clang import: Improved handling of overloaded operators
2020-11-01 15:30:51 +01:00
vilarion
2c34e660b3
Fix #9805 (False positive; Unused function (template)) ( #2871 )
...
* Add test
* Ignore templates with trailing return type as well
2020-11-01 15:10:02 +01:00
Rikard Falkeborn
bd4dc364a7
mathlib: Refactor to use enum class ( #2872 )
2020-11-01 11:47:34 +01:00
Daniel Marjamäki
26e6eed189
Revert "AST: Adjust AST for variable declaration 'char var[] = str;'"
...
This reverts commit 376860f796
.
2020-11-01 11:41:41 +01:00
Daniel Marjamäki
4094274723
TestClangImport: Fix tests
2020-11-01 11:33:01 +01:00
Daniel Marjamäki
5aab1f9692
Clang import: Improved handling of structs
2020-11-01 09:12:58 +01:00
Daniel Marjamäki
226e996e46
Clang import: Improved handling of empty structs/classes
2020-11-01 08:44:38 +01:00
Daniel Marjamäki
7804b28e70
AST: Tweaked debug output
2020-10-31 18:57:48 +01:00
Daniel Marjamäki
597a6eb99c
Clang import: Fix Variable::mTypeStartToken for const argument
2020-10-31 17:43:36 +01:00
Daniel Marjamäki
376860f796
AST: Adjust AST for variable declaration 'char var[] = str;'
2020-10-31 17:05:42 +01:00
vilarion
bc5ec38149
Fix #9806 (False positive: template function can be static) ( #2868 )
...
* Include detecting variadic template functions by matching against endTok instead of startTok.
* Add argument count check for variadic (template) member functions.
2020-10-31 10:02:15 +01:00
shaneasd
a623168942
fix passedByValueError on enums ( #2869 )
2020-10-30 18:32:35 +01:00
Daniel Marjamäki
e044d6e219
Clang import: fixed AST for 'return new S()'
2020-10-29 21:43:35 +01:00
Daniel Marjamäki
9ed4dc4199
Clang Import: Fix AST for 'new S;'
2020-10-29 20:52:09 +01:00
Rikard Falkeborn
de19dc9e3e
Fix #8327 (Memleak with mmap return value check) ( #2864 )
...
Also fix a broken test case related to checking the return value -1
where socket was not defined in the library used in the tests.
This was tested running test-my-pr with 500 packages. The difference was
six fewer FPs.
2020-10-29 13:17:33 +01:00
Daniel Marjamäki
16f4f198eb
Clang import: handle DefaultStmt
2020-10-29 09:48:35 +01:00
Daniel Marjamäki
40156365b8
Adjust cppcheck AST debug output a little bit. Write location for each AST tree
2020-10-28 21:41:21 +01:00
Daniel Marjamäki
4eb829933e
Tokenizer: Fixed unwanted unknownMacro warning for decltype
2020-10-27 09:08:13 +01:00
Daniel Marjamäki
34c8334882
Fixed #9737 (False positive: unreadVariable)
2020-10-25 20:32:45 +01:00
Daniel Marjamäki
05514950af
astyle formatting
...
[ci skip]
2020-10-25 07:12:30 +01:00
miltolstoy
d55874ec37
checkunusedvar: handle initialization list ( #2836 )
2020-10-25 07:11:45 +01:00
Daniel Marjamäki
eb2c0bb6ee
Fix TestExprEngine
2020-10-24 22:53:15 +02:00
Daniel Marjamäki
3876b601d5
Fixed #9476 (Tokenizer: report unknown macro)
2020-10-24 22:12:10 +02: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
Paul Fultz II
64638d82bb
Fix issue 9945: FP: containerOutOfBounds ( #2845 )
2020-10-22 07:41:52 +02:00
Daniel Marjamäki
33844b28ab
Another fix for the crash
2020-10-22 06:59:13 +02:00
Daniel Marjamäki
bcc7c5cd50
Use astIsPointer to avoid crashes
2020-10-22 06:55:48 +02:00
Ken-Patrick Lehrmann
e4a54a24db
Fix regression in CheckCondition ( #2854 )
...
Introduced by e2a81a382f
.
2020-10-20 07:56:41 +02:00
Rikard Falkeborn
2624d791e6
Symboldatabase: Don't set unknown enum values ( #2852 )
...
Previously, if an enum value was set to a value unknown to cppcheck, the
next enum value would erroneously be set to the last set value plus one
(or zero, if no enum value had been set before). This partially fixes
Trac ticket #9647 , in the sense that it no longer sets wrong values for
these enum values. Further improvements to this would be to set the
correct values instead. It also fixes the false positive mentioned in the
comments in the ticket.
2020-10-18 20:41:36 +02:00
Rikard Falkeborn
33739d23aa
Fix #9941 : Return value type of library functions returning unsigned ( #2848 )
...
Fix return value types of library functions returning unsigned.
Previously, the valueType of auto x = f() would be signed even if f()
was specified to return an unsigned type.
This fixes #9941 , which is a regression in cppcheck 2.2 compared to 2.1.
The regression was introduced in 32df807b22
.
2020-10-16 07:56:31 +02:00
Armin Müller
08cef9e815
Typos found by running "codespell" ( #2846 )
2020-10-15 19:24:13 +02:00
Daniel Marjamäki
f1ce5a9101
Fixed #9929 (False positive: suspicious semicolon after macro)
2020-10-09 20:34:20 +02:00
Paul Fultz II
047c3ed6ba
Fix issue 9935: FP: knownConditionTrueFalse value flow doesn't account for virtual functions ( #2839 )
2020-10-09 17:21:27 +02:00
Daniel Marjamäki
586ddf74f1
Clang import; fixed ast for function call with multiple arguments
2020-10-09 07:54:16 +02:00
Daniel Marjamäki
65721dd7a9
Bug hunting; Better handling of constant
2020-10-08 17:24:35 +02:00
Daniel Marjamäki
64608f4e95
clang import; fix symbol database for 'struct Fred { int a; }; int b; void f(int c, int d) { int e; }'
2020-10-06 19:06:10 +02:00
Paul Fultz II
372161c89b
Fix issue 9939: False positive: Reference to temporary returned (static variable) ( #2840 )
2020-10-06 09:16:54 +02:00
Daniel Marjamäki
67cc1776d5
Clang import: fixed return type
2020-10-04 20:02:19 +02:00
Daniel Marjamäki
e3ab688597
Clang import: Fix syntax tree for 'case 1'
2020-10-04 19:33:28 +02:00
Daniel Marjamäki
c3517924d0
Clang import testing: Compare AST
2020-10-04 11:27:31 +02:00
Daniel Marjamäki
b052843655
exprengine: Use and tweak ExprEngine::ArrayValue::MAXSIZE
2020-10-04 11:21:13 +02:00
Daniel Marjamäki
0e32e19184
daca: update WRONG_DATA interface
2020-10-03 15:36:02 +02:00
Daniel Marjamäki
2e20ee9e39
set version 2.2.99
2020-10-03 13:54:17 +02:00
Daniel Marjamäki
17e562a87f
astyle formatting
...
[ci skip]
2020-10-03 11:02:11 +02:00
Paul
828a5e2326
Fix issue 9930: valueFlowLifetime hang
2020-10-03 11:01:53 +02:00
Daniel Marjamäki
c373be0b16
2.2: Update versions
2020-10-03 10:47:35 +02:00
Daniel Marjamäki
8d20d8afb5
Update Copyright year
2020-10-03 09:15:56 +02:00
Daniel Marjamäki
6de91d6386
Fixed #9707 (False positive: unreadVariable, union)
2020-10-02 20:22:22 +02:00
Daniel Marjamäki
63e08689c1
Fix Cppcheck warning
2020-10-02 19:35:24 +02:00
Daniel Marjamäki
ea3a9d658a
Suppressions: Add special case for backwards compatibility. suppression comment after a {.
2020-10-02 18:56:26 +02:00
Daniel Marjamäki
1251d35ba4
Fix SymbolDatabase for 'extern const char ( * x [ 256 ] ) ;'
2020-10-02 08:25:43 +02:00
Daniel Marjamäki
a39e5835d4
Fixed #9925 (False positive: Redundant pointer operation in macro)
2020-09-29 18:27:07 +02:00
Daniel Marjamäki
67b1698752
daca: suppress variableScope warnings in C code as that is usually suppressed in real world. It should make the daca output more relevant.
2020-09-29 17:20:19 +02:00
Daniel Marjamäki
bf3833dad5
Avoid constStatement false positives for 'foo() || x=5'. Found in daca@home.
2020-09-29 13:35:39 +02:00
Daniel Marjamäki
f956dee58a
Tokenizer: Fixed simplification of parentheses in expression 'a=(b,c);'
2020-09-29 12:06:30 +02:00
Daniel Marjamäki
31c800e19e
Fixed false positive: suspicious operator ',' seen in daca@home
2020-09-29 11:32:48 +02:00
Daniel Marjamäki
ad9b2741cd
varid: set varid for 'extern const char (*x[256]);'. This is a partial fix for #9922
2020-09-29 10:53:20 +02:00
Daniel Marjamäki
d901edd4af
Avoid clarifyCalculation warning for 'x % 16 ? 1 : 0' expression. Fixes FP seen in daca@home. It seems likely that the order is understood otherwise the ternary calculation could easily be simplified away.
2020-09-29 08:39:21 +02:00
Daniel Marjamäki
e32ccb591b
Fixed clarifyCalculation fp for 'a % b ? "a" : "b"'. seen in daca@home.
2020-09-29 08:29:23 +02:00
IOBYTE
4e4108dc8b
fix daca insighttoolkit crash in template simplifier ( #2826 )
...
Don't count deleted instantiations in the recursive count.
I can't reduce the daca code because creduce requires a preprocessed
file to reduce and the problem doesn't show up when the file is
preprocessed with cppcheck.
There is no test because I couldn't reduce the problem files.
Co-authored-by: Robert Reif <reif@FX6840>
2020-09-28 22:51:13 +02:00
Daniel Marjamäki
bf236e91d7
Fixed #9918 (False positive: autoVariable pointer is NULLed later)
2020-09-28 22:48:57 +02:00
Daniel Marjamäki
8395522390
Fixed #9919 (False positive: clarifyCalculation for code: flags & ZRL_EOL_NUL ? '\0' : '\n')
2020-09-28 19:18:34 +02:00
Daniel Marjamäki
4c9db17742
Tokenizer: replace all or none of the alternative tokens in a translation unit
2020-09-28 19:01:31 +02:00
Daniel Marjamäki
fa42d8c49c
Fixed #9920 (Tokenizer: The keyword is not replaced, leads to false positive)
2020-09-28 16:35:50 +02:00
Daniel Marjamäki
84b8f32fd4
daca: group warnings for prohibited functions
2020-09-27 21:42:07 +02:00
Daniel Marjamäki
2748201d73
Fixed #9782 (Segmentation fault due to broken AST)
2020-09-27 20:41:09 +02:00
Daniel Marjamäki
ba84303501
Fixed #9680 (false positive: style: Variable 'x' is assigned a value that is never used with smart pointers)
2020-09-27 19:15:15 +02:00
Daniel Marjamäki
3b39433e21
Fixed Cppcheck warnings
2020-09-26 22:30:59 +02:00
Daniel Marjamäki
7bb82c5df7
Fixed #9901 (False positive: variable is assigned value that is not used 'if (--N == 0)')
2020-09-26 22:13:05 +02:00
Daniel Marjamäki
0ec77879ea
Fix crash in createAST when checking wiggle in daca@home
2020-09-26 19:22:24 +02:00
Daniel Marjamäki
5578b09452
More fixing for #9914 . New warning id and warning message when variable expression is explicitly hidden.
2020-09-26 13:49:47 +02:00
Daniel Marjamäki
05b0a0f970
Make duplicateAssignExpression warnings inconclusive for 'x&&false' etc. ( #9914 )
2020-09-26 10:50:58 +02:00
Paul Fultz II
887b40e08b
Fix issue 9916: False positive: duplicateAssignExpression when it's checked if variables have initial value later ( #2825 )
2020-09-26 10:31:40 +02:00
Daniel Marjamäki
5856fef83b
Fixed #9914 (False positive: knownArgument for 'x && false')
2020-09-25 20:27:16 +02:00
Daniel Marjamäki
bbd3a992b8
Fix output when note contains
2020-09-25 19:04:22 +02:00
Daniel Marjamäki
485153c930
Limit variableScope check. Do not check C code if all local variables are declared at function level.
2020-09-25 08:34:47 +02:00
Daniel Marjamäki
093ff58f5f
Fix crash in cbmc detected with daca@home
2020-09-24 20:48:26 +02:00
Daniel Marjamäki
801cc8d331
Fixed knownArgument false positive for pointer
2020-09-24 19:48:20 +02:00
Daniel Marjamäki
c08e1a9a94
Fix knownArgument false positive when sizeof is used
2020-09-24 19:43:39 +02:00
Daniel Marjamäki
514b7f4da4
Fixed #9906 (False positive: constParameter (function pointer))
2020-09-23 22:10:47 +02:00
Paul Fultz II
d9eacaecbb
Fix issue 9842: ValueFlow: wrong handling of ?, seems to think that the whole expression is a condition ( #2821 )
2020-09-23 07:45:03 +02:00
Oliver Stöneberg
2e24cc1434
checkother.h: added missing newline in classInfo - fixes tests ( #2818 )
2020-09-21 21:44:46 +02:00
Daniel Marjamäki
107ee57e7a
Fixed #9909 (False positive: knownArgument for calculation 'self->maxsize * sizeof(intptr_t)')
2020-09-21 20:02:55 +02:00
Daniel Marjamäki
bca3605f77
astyle formatting
2020-09-21 19:48:04 +02:00
Oliver Stöneberg
7189b303ae
fixed some modernize-loop-convert clang-tidy warnings ( #2815 )
2020-09-21 19:30:47 +02:00
Paul Fultz II
7b6d3f8061
Fix issue 9907: False positive: knownEmptyContainer after function call with :: ( #2814 )
2020-09-20 22:37:28 +02:00
Daniel Marjamäki
730b95331e
Fixed #9905 (False positive: known argument 'header.length()')
2020-09-20 20:17:10 +02:00
Daniel Marjamäki
c563944fdd
astyle formatting
2020-09-20 20:14:30 +02:00
Paul Fultz II
857722f859
Fix issue 9711: FP knownConditionTrueFalse for variable modified via pointer ( #2813 )
2020-09-20 14:27:09 +02:00
Paul Fultz II
c2e8051196
Fix issue 9904: False positive: duplicateCondition when modifying variable in lambda ( #2811 )
2020-09-18 07:44:26 +02:00
Paul Fultz II
e5d0ffdbe7
Fix issue 9900: False positive: Returning lambda that captures local variable 'x' that will be invalid when returning. ( #2809 )
2020-09-17 08:33:52 +02:00
Paul Fultz II
782684a7cc
Fix issue 9530: False positive: Reference to temporary returned when using initializer lists ( #2796 )
2020-09-17 08:33:16 +02:00
Paul Fultz II
11c99d7387
Fix issue 9880: False positive: danglingLifetime ( #2810 )
2020-09-17 07:23:38 +02:00
Paul Fultz II
ebbff08932
Fix issue 9899: False positive: Non-local variable will use object that points to local variable ( #2808 )
2020-09-15 07:11:52 +02:00
Daniel Marjamäki
3459f0da32
Fixed #9812 (False positive; syntax error 'using array_p = const array_t *;')
2020-09-14 21:59:58 +02:00
shaneasd
53a0760fdf
Improve ast generation for templated function parameters ( #2803 )
2020-09-14 18:44:50 +02:00
Paul Fultz II
a42976d656
Fix issue 9898: false positive: knownConditionTrueFalse ( #2806 )
2020-09-14 18:43:11 +02:00
Daniel Marjamäki
4dd85cfbe0
Merge pull request #2802 from rikardfalkeborn/9228-fix-fn-with-realloc-and-null-assignment
...
Improve memleakOnRealloc with assignment to NULL
2020-09-14 11:04:29 +02:00
Paul Fultz II
94850fec3f
Fix issue 9897: False positive: nullPointerRedundantCheck ( #2805 )
2020-09-14 09:17:29 +02:00