Commit Graph

12350 Commits

Author SHA1 Message Date
Daniel Marjamäki 0ac4de2a5e Small refactoring 2020-11-09 19:30:05 +01:00
Daniel Marjamäki 8b52ed590e Clang import: Better handling of const methods 2020-11-09 14:50:34 +01:00
Daniel Marjamäki 06909df8f5 Clang import: better handling of ArrayToPointerDecay implicit casts 2020-11-08 19:53:28 +01:00
Daniel Marjamäki 1c742b7995 Clang import: Handle AccessSpecDecl 2020-11-08 17:02:19 +01:00
Daniel Marjamäki 818e1574ad Fix Cppcheck self check warning 2020-11-08 10:57:48 +01:00
Daniel Marjamäki 1078855029 Clang import: Full name for methods 2020-11-08 10:31:48 +01:00
Daniel Marjamäki 87323b33bd Clang import: Fixed problems when handling CXXConstructorDecl 2020-11-08 01:17:34 +01:00
Daniel Marjamäki 565e67d373 Clang import: Ignore VisibilityAttr 2020-11-07 22:27:11 +01:00
Daniel Marjamäki 1c2e480449 Proper fix for test-clang-import.py failure 2020-11-07 18:12:47 +01:00
Daniel Marjamäki ff17d3e7c6 Clang import: Better handling of scope types 2020-11-07 15:02:36 +01:00
Daniel Marjamäki 88a35d2253 Fix CodeQL warning, Multiplication result converted to larger type 2020-11-06 19:50:05 +01:00
Daniel Marjamäki 52b88bcee3 Fix CodeQL warning, Multiplication result converted to larger type 2020-11-06 19:44:32 +01:00
Georgy Komarov 80dee36e68
library: Add new warning: ignoredReturnErrorCode (#2877)
* library: Add optional "type" attribute to "use-retval"

Added an optional "type" attribute to "use-retval" nodes in the
configuration. When the return type of a function configured with
`<use-retval type="error-code"\>` node does not used, the new style
error "ignoredReturnErrorCode" will be generated.

* Fix and improve patch after the initial review

* Fixed severity level and [[nodiscard]] attribute

* Fix incorrect condition

* Remove redundant condition
2020-11-05 13:35:52 +01:00
Jesse Boswell f70e8de315
Fix #9567 (Inline suppression of unusedFunction errors not working when using compile database) (#2870) 2020-11-04 21:01:48 +01:00
uhziel aad29ddb9a
fix an error in Tokenizer::simplifyTypedef() (#2880) 2020-11-04 13:32:31 +01:00
Daniel Marjamäki ae1b9cb14e SymbolDatabase: Improved function matching in C code 2020-11-04 07:17:17 +01:00
Daniel Marjamäki 198bbc8a5a Clang import: Better type handling 2020-11-03 21:37:28 +01:00
Daniel Marjamäki 8956ecb5fc Clang import: Fixed data for inline static functions 2020-11-03 17:52:53 +01:00
Daniel Marjamäki e053066d8b Clang import: Fixed Variable::mTypeStartToken and Variable::mTypeEndToken for unnamed parameters 2020-11-02 20:58:43 +01:00
Oliver Stöneberg 488813d00f
added validateCFG and checkcfg targets to CMake / some refactorings (#2687) 2020-11-02 20:16:15 +01:00
Daniel Marjamäki a2a948a311 Clang Import; Better handling of derived classes 2020-11-01 20:32:42 +01:00
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