Commit Graph

10430 Commits

Author SHA1 Message Date
Daniel Marjamäki 8a1c16a560 Tokenizer: add daca debug messages when right angle brackets in templates are not handled well 2020-11-29 16:07:56 +01:00
Daniel Marjamäki 7112f69d7b Fixed bug in fixAngleBrackets 2020-11-29 12:56:13 +01:00
Daniel Marjamäki e2debac882 Fix testcases 2020-11-29 08:46:42 +01:00
Daniel Marjamäki fd75837494 Tokenizer: Remove extra 'template' keywords 2020-11-28 21:57:06 +01:00
Daniel Marjamäki 5b89b179ec Detect syntax error when script is checked 2020-11-28 14:41:05 +01:00
Daniel Marjamäki af26697ceb AST: Generate proper AST for 'f = []() -> foo&& {}' 2020-11-28 06:53:46 +01:00
Daniel Marjamäki 484b68c550 astyle formatting 2020-11-28 05:52:35 +01:00
miltolstoy 5d299016f1
feat: analyze function side effects (#2901) 2020-11-26 17:34:42 +01:00
orbitcowboy 0e8556e6ed Activated basic runtime checks for 'Debug'-testrunner builds with MSVS as described here: https://docs.microsoft.com/de-de/cpp/build/reference/rtc-run-time-error-checks?view=msvc-160 2020-11-26 09:29:59 +01:00
Daniel Marjamäki 96392aa212 Clang import: better handling of templates 2020-11-24 22:02:59 +01:00
Daniel Marjamäki 788abfa8a4 Clang import: better handling of CXXMethodDecl in getSpelling 2020-11-24 19:20:30 +01:00
IOBYTE 1ea89bcad8
add support for template constructors (#2911) 2020-11-24 07:21:37 +01:00
Daniel Marjamäki b4db52bf61 Fixed #9860 (wrong ast for placement new 'new ( uBAR ? uBAR : sizeof ( T ) ) T') 2020-11-23 22:03:50 +01:00
Daniel Marjamäki 4a2e082d85 Revert "GUI: restore default tab in ProjectFileDialog"
This reverts commit 39564c9e6c.
2020-11-23 20:18:06 +01:00
Daniel Marjamäki 39564c9e6c GUI: restore default tab in ProjectFileDialog 2020-11-23 19:27:14 +01:00
Daniel Marjamäki 208a4a4548 Check unused templates by default 2020-11-23 18:29:08 +01:00
Daniel Marjamäki f6e7a66f42 TestConstructors: Unremove a test case 2020-11-22 18:17:40 +01:00
Daniel Marjamäki 2cd8ea83a7 Fixed #9860 (unused template not removed properly by default) 2020-11-22 16:43:36 +01:00
Wolfgang Stöggl 8ac55a8534
Add find_package(tinyxml2) to CMake builds (#2691)
So far, the cmake files of Cppcheck needed to be patched in order to
use installed tinyxml2 instead of the bundled version of tinyxml2.
- Introduce the CMake option USE_BUNDLED_TINYXML2 with a default value
  of ON. This preserves the behavior as in the past and uses the
  bundled version under externals/tinyxml2 by default.
- Usage of the installed tinyxml2 version of a system can be enabled
  now using -DUSE_BUNDLED_TINYXML2=OFF as a cmake parameter.
- Some Linux distros do not install tinyxml2*.cmake files, which are
  required to find tinyxml2 using find_package().
  Try first using find_package(tinyxml2 QUIET) and if this fails, try
  again using find_library(tinyxml2_LIBRARY tinyxml2)
2020-11-22 08:57:07 +01:00
Paul Fultz II 4a8a78a925
Fix issue 10002: False positive: constParameter with reference to pointer (#2918) 2020-11-22 08:47:24 +01:00
Paul Fultz II f6399c4cba
Fix issue 9980: FP nullPointerRedundantCheck - condition after while loop (#2912) 2020-11-20 09:36:09 +01:00
Daniel Marjamäki 9c27ba835d astyle formatting 2020-11-19 21:25:49 +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
IOBYTE c4b3d4cd77
fix #9983 (TemplateSimplifier: template not simplified : f(0,0);) (#2905)
Currently template type deduction for functions only works for single
template argument single function argument functions with a literal
argument.

This patch starts to add support for single template argument multiple
function argument functions.  It correctly handles functions with
multiple arguments of the same type. It also handles a mix of template
and non-template arguments.

It does not add support for overloading non-template arguments.
It does not add support for multiple parameter template functions.
It does not add support for type deduction from variable arguments.

Co-authored-by: Robert Reif <reif@FX6840>
2020-11-17 06:51:32 +01:00
Daniel Marjamäki 22d6160624 Improve handling of decltype 2020-11-16 20:11:26 +01:00
Daniel Marjamäki c7cbe7f2d3 rename externals/tinyxml to externals/tinyxml2 2020-11-16 09:11:53 +01:00
Daniel Marjamäki 8b0699cd6a Revert "improved decltype() handling"
This reverts commit 6e8f77c519.
2020-11-15 21:32:05 +01:00
Daniel Marjamäki 6e8f77c519 improved decltype() handling 2020-11-15 20:58:17 +01:00
Daniel Marjamäki 7878eb2512 AST: Do not generate AST for decltype 2020-11-15 16:47:36 +01:00
Daniel Marjamäki 54a93c4374 Fixed #9452 (FP syntaxError - _Pragma before struct with two constructors) 2020-11-15 15:03:47 +01:00
Daniel Marjamäki 6236beeb3f Fixed #9950 (Wrong severity for redundantAssignInSwitch) 2020-11-15 13:09:28 +01:00
Ken-Patrick Lehrmann 7c3afa0b36
9955: Fix ast when throwing a cast (#2900)
```
throw (std::string)"Error: " + strerror(errnum);
```
would result in a broken ast:
```
throw
`-::
  |-std
  `-string
```
instead of
```
throw
`-+ 'signed char *'
  |-( 'container(std :: string|wstring|u16string|u32string)'
  | `-"Error: " 'const char *'
  `-( 'signed char *'
    |-strerror
    `-errnum 'signed int'
```
2020-11-15 10:37:29 +01:00
Falital 2e2d4a0055
Added Hash to plist file names (#2898) 2020-11-13 15:52:24 +01:00
Rikard Falkeborn 324e267559
getSizeOf: Handle long double (#2888) 2020-11-11 22:51:17 +01:00
Daniel Marjamäki 4330a43acb Fixed #9933 (FP: uninitvar when reading to struct) 2020-11-11 22:47:23 +01:00
Daniel Marjamäki bfa8c6fb98 Fixed cppcheck warning and corrected checkHeaders test 2020-11-11 15:28:32 +01:00
Daniel Marjamäki c95b0d2a51 Fixed #9977 (Template simplifier does not simplify in header) 2020-11-11 09:50:51 +01:00
Daniel Marjamäki 7182da5c8e astyle formatting 2020-11-11 09:17:54 +01:00
Rikard Falkeborn 829c543331
TestCondition: Don't warn when sizeof is involved (#2896) 2020-11-11 08:01:11 +01:00
IOBYTE e785885b4d
fix #9975 (Template method not simplified) (#2894) 2020-11-10 21:19:04 +01:00
Paul Fultz II bd7e915c20
Add generic reverse valueflow (#2878) 2020-11-10 16:00:55 +01:00
Ken-Patrick Lehrmann 79bdd64689
Fix false positive memoryleak (#2882)
```
int *f() {
  int *p = static_cast<int *>(realloc(nullptr, 10));
  if (!!(!p)) {
    return nullptr;
  }
  return p;
}

```
would give
```
memleak2.cpp:4:5: error: Memory leak: p [memleak]
    return nullptr;
    ^
```
Because of the additional `!!̀ .
2020-11-10 15:59:51 +01:00
Paul Fultz II ae6f611df0
Fix issue 9973: False positive: mismatching iterator container, reference (#2893) 2020-11-10 09:38:05 +01:00
Daniel Marjamäki bd5fc4b579 Clang import: Fixed variable type for pointers 2020-11-10 09:35:41 +01:00
Daniel Marjamäki bd5b2133ab Clang import: Variable::isReference() should return true for r-value references also 2020-11-09 21:00:48 +01:00
Daniel Marjamäki 5cfe2e319c Clang import: Fix Variable::isRValueReference 2020-11-09 20:44:46 +01:00
Daniel Marjamäki 970beaa79a Clang import: Fix Variable::isReference 2020-11-09 20:35:00 +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 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 b8e0cdcdb4 Travis: temporary hack to make test-clang-import.py happy 2020-11-07 17:23:56 +01:00
Daniel Marjamäki ff17d3e7c6 Clang import: Better handling of scope types 2020-11-07 15:02:36 +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
Rikard Falkeborn a7f6621fc0
cfg: cppunit: Fix FP with compareBoolExpressionWithInt within CPPUNIT_ASSERT_EQUAL (#2879) 2020-11-04 07:48:53 +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 eece8ee66b astyle formatting 2020-11-03 21:08:21 +01:00
Daniel Marjamäki 8956ecb5fc Clang import: Fixed data for inline static functions 2020-11-03 17:52:53 +01:00
Oliver Stöneberg 98946143f6
Fix #9964 (false positive: compareBoolExpressionWithInt with ASSERT_FALSE() and --library=googletest) (#2876) 2020-11-03 10:20:25 +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 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
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 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 6d0b78433b astyle formatting 2020-10-29 21:43:56 +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 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 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 47914b9960 Crash: Add regression test 2020-10-22 07:40:06 +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
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 40faca7dd9 Fix TestClangImport 2020-10-06 23:19:32 +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