Commit Graph

2645 Commits

Author SHA1 Message Date
Daniel Marjamäki fa42d8c49c Fixed #9920 (Tokenizer: The keyword is not replaced, leads to false positive) 2020-09-28 16:35:50 +02:00
Oliver Stöneberg 7189b303ae
fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +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
Daniel Marjamäki 687b44dbb7 Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02:00
Daniel Marjamäki e802d85315 Fixed #9445 (Syntax error on typeof word in C) 2020-09-08 17:12:54 +02:00
Daniel Marjamäki c0ef640304 Fixed #9881 ((Regression) Hang with operator() in function call) 2020-09-07 21:32:29 +02:00
Daniel Marjamäki cfd41fea83 Fixed #9879 (Tokenizer: Better handling of operator() '(*this)(...)') 2020-09-07 20:07:21 +02:00
Daniel Marjamäki 136ac2c643 Fixed #9266 (handle operator() better) 2020-09-06 21:02:06 +02:00
Daniel Marjamäki 9a943e7616 misra: rewrote rule 12.3 2020-09-06 11:33:37 +02:00
Daniel Marjamäki 7969bf7ae8 Token: Add 'isSplittedVarDecl attribute 2020-09-06 11:02:22 +02:00
Daniel Marjamäki 12d51ae5c4 Fixed #9809 (Tokenizer; Fix handling of variable declaration with @) 2020-09-02 13:04:33 +02:00
IOBYTE 8774e97f26
fix #9771 (Syntax error; operator != <> ()) (#2757) 2020-08-26 18:39:33 +02:00
Daniel Marjamäki 72fa5f2e27 Fixed #9752 (ValueFlow: Uninit after assignment with '&') 2020-08-05 22:57:06 +02:00
Georgy Komarov 6bc13080ee
Simplify condition 2020-07-18 07:07:20 +03:00
Georgy Komarov 382f21a5c9
Fixed crash on garbage code: comparisson with an empty second operand
This will fix #9774.
2020-07-18 07:02:12 +03:00
Daniel Marjamäki ddd21a260f Fixed #6978 (False positive: unusedLabel shown for labels that are used in some preprocessor configurations) 2020-06-30 18:26:24 +02:00
Daniel Marjamäki 0583763cc6 Fixed #3088 (False positive: Dont report "struct or union member is never used" for structs with __attribute__((packed)) or #pragma pack(push)) 2020-06-30 11:00:40 +02:00
Daniel Marjamäki af6e76d623 Fixed #9787 (Better handling of user defined literals) 2020-06-25 22:06:34 +02:00
Simon Martin 1705d096f7
Simplify empty anonymous namespaces. (#2673) 2020-06-07 13:49:04 +02:00
Ken-Patrick Lehrmann a45c7752a5
9185: Don't syntax error on nested lambdas (#2672) 2020-06-07 08:58:12 +02:00
Ken-Patrick Lehrmann 99ff04f617
9757: skip template parameters when computing scope (#2670)
The template parameter is confusing simplifyUsing: it does not compute
properly the scope, and we end up replace "type" in "to_string" with
"void", then later "void" is removed and we have an internal error.
2020-06-06 17:51:15 +02:00
Paul Fultz II eed2e829a7
Revert "Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list." (#2666)
This reverts commit 187cde183d.
2020-05-30 11:23:22 +02:00
PKEuS 187cde183d Cleanup: Removed Tokenizer::simplifyTokenList2. As a side-effect, rules for "simple" token list are now executed on normal token list. 2020-05-29 21:21:07 +02:00
Daniel Marjamäki 67115491ea Fixed #9739 (Tokenizer: simplifyTypedef: wrong simplification in using) 2020-05-29 11:16:49 +02:00
Daniel Marjamäki 7ff692341e Fixed #9730 (Regression: TEXT macro not handled in windows code) 2020-05-28 22:03:16 +02:00
Daniel Marjamäki 4d5fe6ec5e astyle formatting
[ci skip]
2020-05-26 23:28:19 +02:00
Oliver Stöneberg 4f68d85633
optimized non-matchcompiled Token::simpleMatch() a bit (#2640) 2020-05-26 20:13:56 +02:00
Daniel Marjamäki f7f26ffe90 Tokenizer: Better handling of c alternative tokens in const method 2020-05-25 15:07:23 +02:00
Oliver Stöneberg 37bc0483a4
made check.h less heavy (#2633) 2020-05-23 07:16:49 +02:00
Paul Fultz II 8301fa8244
Fix issue 8144: valueFlowBeforeCondition: struct (#2645) 2020-05-21 08:47:48 +02:00
PKEuS 662745b504 Fixed several coverity messages 2020-05-20 18:54:16 +02:00
PKEuS c155062cf2 Optimization: Speed up SymbolDatabase creation and Tokenizer::findGarbageCode() by using Token::isKeyword() for pre-checks 2020-05-19 13:48:15 +02:00
PKEuS f6788c0472 Fixed Token::isKeyword: Actually set this flag to a reasonable value in all code paths 2020-05-19 13:47:25 +02:00
PKEuS c9d8f607df Optimization: Reduced peak memory usage (30% in my test case) by immediately deleting simplecpp::TokenList while creating the cppcheck TokenList. 2020-05-19 12:08:17 +02:00
PKEuS 09a30bd6b5 Optimization: Speed up Tokenizer::findGarbageCode() (by 15% in my test case) by avoiding iterating through token list multiple times 2020-05-19 08:54:47 +02:00
PKEuS d6390dbd14 Optimization: Improved performance of simplifyTypedef for code with lots of typedefs
20% performance gain when checking ExtremeTuxRacer sourcecode (with glext.h available)
2020-05-19 08:35:13 +02:00
Daniel Marjamäki 9eda399323 Less strict unknownMacro 2020-05-17 19:12:16 +02:00
Daniel Marjamäki 08ddd84780 Update copyright year 2020-05-10 11:16:32 +02:00
Daniel Marjamäki 3e0218299b Revert "Update copyright year"
This reverts commit 6eec6c4bd5.
2020-05-10 11:13:05 +02:00
Daniel Marjamäki 6eec6c4bd5 Update copyright year 2020-05-10 11:11:34 +02:00
Daniel Marjamäki 00d1091506 Tokenizer: operator handling, fix tests 2020-05-04 23:00:51 +02:00
Daniel Marjamäki 06cb0e99d1 Tokenizer: Fix syntax error when operator* is called 2020-05-04 21:33:30 +02:00
Daniel Marjamäki 47c998e52d Fixed #9689 (setVarId: wrong varid when 'not' is used) 2020-04-25 14:42:45 +02:00
Oliver Stöneberg 1af959af2c
fixed -Wextra-semi-stmt Clang warnings (#2553)
* fixed -Wextra-semi-stmt Clang warnings

* adjusted REDIRECT macro to require a semicolon

* testmathlib.cpp: rolled back accidental change
2020-04-21 17:27:51 +02:00
Daniel Marjamäki bda73600e0 Tokenizer: Improved removal of unused template (#9588) 2020-04-20 20:48:22 +02:00
Zorgovskiy 08fc956990
Fixes issue #9664 (#2614) 2020-04-20 08:59:35 +02:00
Daniel Marjamäki de53f63f76 Fixed #9665 (Tokenizer::setVarId: for loop variables) 2020-04-18 12:08:53 +02:00
Daniel Marjamäki e4bea02cad Fixed #7578 (varid not set for 'pointer to array' member variable in method) 2020-04-15 20:56:21 +02:00
Daniel Marjamäki 266c8d2c09 Remove temporary daca bailouts 2020-04-15 19:54:56 +02:00
Daniel Marjamäki 98be091d80 Fixed typedef simplification for array of function pointers 2020-04-13 16:28:01 +02:00
Oliver Stöneberg 2c1e36e63e
cleaned up includes based on include-what-you-use (#2600)
* cleaned up includes based on include-what-you-use

* check.h: trying to work around Visual Studio 2012 bug

* fixed Visual Studio compilation
2020-04-13 13:44:48 +02:00
shaneasd 82c09f243b
Maybeunusedsupport (#2570)
* Add rudimentary support for [[maybe_unused]]

* Add more test cases. use the symboldatabase rather than reparsing. Fix travis error.

* test review actions

* change var to usage._var
2020-04-12 20:35:54 +02:00
Daniel Marjamäki 97b04ba9a7 Syntax check: Using keyword in global scope 2020-04-11 17:36:22 +02:00
Daniel Marjamäki e8e3c2660d Detect syntax error 'x ==> y' 2020-04-11 11:05:27 +02:00
Daniel Marjamäki 05769e8dcc Code cleanup 2020-04-10 13:14:38 +02:00
Daniel Marjamäki 0725c2290c Tokenizer: Do not simplify function pointers to normal pointers as we loose important information 2020-04-10 11:53:32 +02:00
Daniel Marjamäki 8e9d7290b2 Tokenizer::simplifyTypedef: Better handling of r-value references 2020-04-08 22:40:45 +02:00
Oliver Stöneberg 1dd8d4afaf
fixes for Clang and clang-tidy 10 (#2588)
* clang_tidy.cmake: added clang-tidy-10 to program list

* fixed -Wrange-loop-construct Clang warnings

* fixed readability-qualified-auto clang-tidy warnings

* .clang-tidy: actually disable clang-analyzer-* warnings

* .clang-tidy: disabled some new warnings introduced with clang-tidy-10
2020-04-04 11:44:59 +02:00
Daniel Marjamäki ac45bf7af2 Small refactoring 2020-04-04 11:19:39 +02:00
Daniel Marjamäki e0acd1abf8 Tokenizer: Report unknown macro that contains '.x=..' argument 2020-04-04 10:32:56 +02:00
Daniel Marjamäki 7577bdb1df DACA: Try to avoid some crashes/hangs for the most crazy code so we can focus on most serious bugs first 2020-03-31 11:33:38 +02:00
Daniel Marjamäki 1173186876 Fixed daca@home crash by stopping for unknown macro 'MACRO(a();b();)' 2020-03-12 13:28:09 +01:00
Daniel Marjamäki 900b99fbd8 Tokenizer; Report unknown macro used in function declaration 2020-03-10 20:22:46 +01:00
Daniel Marjamäki 5df6d5bc7c Tokenizer; Warn about unknown macro used in string concatenation 2020-02-28 21:52:01 +01:00
Daniel Marjamäki 84995485ea VarId: fixed varids for 'for (auto [x,y]: xy)' 2020-02-27 07:18:07 +01:00
Daniel Marjamäki f07a71e3e1 Report unknown macros for pattern '%name% %num%' 2020-02-22 11:57:36 +01:00
Daniel Marjamäki ec8c733afb Improved Qt simplification 2020-02-21 19:04:21 +01:00
Daniel Marjamäki 6f6f9dd5bc Tokenizer: Throw unknownMacro in non-executable scope 2020-02-19 21:12:58 +01:00
Daniel Marjamäki ae0a73a538 Fixed #9618 (isCast flag not set for c++ casts) 2020-02-16 16:46:40 +01:00
Paul Fultz II 921887a281
Use valueFlowGeneric for valueFlowForwardExpression (#2537) 2020-02-16 16:02:22 +01:00
Daniel Marjamäki dcee189146 Tokenizer::setVarId: better handling of decltype() 2020-01-29 17:40:22 +01:00
Simon Martin 2840173a72 Ticket #9569: Do not substitute type aliases within enum definitions. (#2504) 2020-01-25 10:18:37 +01:00
Simon Martin 224a41361d Ticket #9572: Properly detect designated initializers. (#2496) 2020-01-25 10:14:16 +01:00
Rikard Falkeborn 7514544d94 Fix #8758 (add syntax error for invalid code) (#2466) 2020-01-01 15:46:09 +01:00
Daniel Marjamäki c84ba10b37 Fixed #8774 (Wrong handling of function with name 'or') 2019-12-19 19:22:39 +01:00
Daniel Marjamäki f614d32d6a Fixed #9519 (Syntax error on valid C++ 'enum {} (a)') 2019-12-15 08:40:04 +01:00
IOBYTE 0e4efea530 fix #9539 (Syntax error for valid C++14 code) (#2446) 2019-12-12 20:50:20 +01:00
RobkeBaer 370196a14c Fix extern c typedef syntax error (#2438)
* Fix extern c typedef syntax error

* Fix extraWhiteSpaceError

* Move test from testgarbage to testtokenize
2019-12-12 13:51:14 +01:00
IOBYTE f637d97080 Fix 9509 (Syntax error on empty attribute list) (#2423) 2019-12-06 05:17:19 +01:00
IOBYTE 5979eec2c0 Fix 9518 (Syntax error on valid C++) (#2424) 2019-12-05 20:51:36 +01:00
Paul Fultz II f77347d7b4 Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr) (#2411)
* Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr)

* Formatting
2019-12-01 14:53:03 +01:00
Daniel Marjamäki ebd32cfd73 Syntax error: if (retval==) 2019-11-23 18:50:46 +01:00
IOBYTE fb1d60bfb1 fix syntax error for num.operator std::string()[0] (#2389) 2019-11-23 17:42:24 +01:00
IOBYTE df952926f8 fix syntax error for a.operator++() ? a.operator--() : 0 (#2382) 2019-11-20 22:13:32 +01:00
Sebastian c990d10ffa
Check for JSON error when parsing addon .json files + fixes (#2374)
* cppcheck.cpp: Check for JSON error when parsing addon .json files

This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().

* naming.json: Fix missing comma

* CLI: Fix naming violations detected by addon naming.py via naming.json

* Addon naming: Add argument for validating names of constants

* LIB: Rename functions/variables so they are valid, loosen naming rules

* GUI: Fix naming violations
2019-11-20 15:37:09 +01:00
IOBYTE 7f6ebaa6b2 fix syntax error for VTK_LEGACY_BODY(vtkMatrix3x3::operator[], "VTK 7.0"); (#2372) 2019-11-18 06:38:53 +01:00
IOBYTE 754c1fff66 fix syntax error for conversion operator for type with global namespace (#2365)
* fix syntax error for conversion operator for type with global namespace

* fix syntax error when taking address of operator function

* fix syntax error for using ::operator "" _a;

* fix syntax error for template<> void operator "" _h<'a', 'b', 'c'>() {}

* fix syntax error for operator in parentheses
2019-11-16 08:03:13 +01:00
Daniel Marjamäki b9835fd4f9 Fixed #9445 (Syntax error on typeof word in C) 2019-11-15 21:20:57 +01:00
IOBYTE 3a617fa04a Fix #9472 (Syntax error on valid C++ code) (#2363)
There are probably a lot more valid code patterns that generates syntax
errors so I added "operator" to the error message to make it easier to
find them.
2019-11-15 07:03:57 +01:00
Daniel Marjamäki 7e0fc4fb00 Tokenizer: Detect more syntax errors when operator does not have operands 2019-11-14 21:18:31 +01:00
IOBYTE 2eb575d990 Fix #9468 (Syntax error on valid C++) (#2358) 2019-11-14 09:26:21 +01:00
IOBYTE 0fed6f0091 fix clang testsuite crash (#2341) 2019-11-09 18:00:21 +01:00
Daniel Marjamäki 8c8952ae7c Fixed #9324 (FP compareBoolExpressionWithInt - when using C++ and/or operator synonyms) 2019-11-03 12:53:30 +01:00
Daniel Marjamäki 791242ea78 Fixed #6975 and #9376 (Tokenizer: unknown macro without semicolon) 2019-11-02 19:34:19 +01:00
IOBYTE 3f0ef01154 Fix #9446 (Syntax error on valid C++ code) (#2316) 2019-11-01 09:11:29 +01:00
Daniel Marjamäki b96a347914 Tokenizer: Report unknown macro when argument list contains if/for/while/switch 2019-10-30 19:36:19 +01:00
Rikard Falkeborn 5c061c1c12 Set correct type and size of string and char literals (#2275)
* Set correct type and size of string and char literals

Use that string and char literal tokens store the prefix. This makes
it possible to distinghuish between different type of string literals
(i.e., utf8 encoded strings, utf16, wide strings, etc) which have
different type.

When the tokens holding the string and character values have the correct
type, it is possible to improve Token::getStrSize() to give the correct
result for all string types. Previously, it would return the number of
characters in the string, i.e., it would give the wrong size unless
the type of the string was char*.

Since strings now can have different size (in number of bytes) and
length (in number of elements), add a new helper function that returns
the number of characters. Checkers have been updated to use the correct
functions.

Having the size makes it possible to find more problems with prefixed
strings, and to reduce false positives, for example in the buffer
overflow checker.

Also, improve the stringLiteralWrite error message to also print the
prefix of the string (if there is one).

* Add comment and update string length
2019-10-20 07:11:57 +02:00
IOBYTE e4d2e9d2af Fix #9421 (syntaxError on incomplete code (from z3)) (#2274) 2019-10-16 20:56:53 +02:00
Rikard Falkeborn 297360920a Keep prefix in string and char literals (#2272)
Keeping the prefix in the token allows cppcheck to print the correct
string and char literals in debug and error messages.

To achieve this, move some of the helper functions from token.cpp to
utils.h so that checks that look at string and char literals can reuse
them. This is a large part of this commit.

Note that the only user visible change is that when string and char
literals are printed in error messages, the prefix is now included.

For example:

	int f() {
		return test.substr( 0 , 4 ) == U"Hello" ? 0 : 1 ;
	};

now prints U"Hello" instead of "Hello" in the error message.
2019-10-16 11:41:33 +02:00
Daniel Marjamäki 62d972061b astyle formatting
[ci skip]
2019-10-14 19:41:51 +02:00