Commit Graph

2538 Commits

Author SHA1 Message Date
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
Sebastian 267d23f1b8
gnu.cfg: Define `__typeof__` as `typeof`, fix simplifyTypedef() (#2260)
`__typeof__` is just an alternative keyword for `typeof`, see
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
Since `typeof` is handled in several checkers it makes sense to define
`__typeof__` as `typeof`.
Tokenizer::simplifyTypedef(): Use `typeof` instead of `__typeof__` to
be consistent with the rest of the code.
2019-10-14 08:20:22 +02:00
KenPatrickLehrmann 5a08ac361a Better handle const/noexcept methods (#2211)
* Better handle const/noexcept methods/conversion operator

const or noexcept in a method / (conversion) operator definition were
badly parsed, ending in a bad ast.
This patch tries to make it better, at least making the ast less bad,
so as to avoid errors in later checks.

* Fix parsing of some operator

It is still very broken, but at least, it does not fail.

Here is the previous error:
```
TestSimplifyTypedef::simplifyTypedef129
terminate called after throwing an instance of 'InternalError'

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
 #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
 #1  0x00007ffff612a801 in __GI_abort () at abort.c:79
 #2  0x00007ffff6b1d957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #3  0x00007ffff6b23ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #4  0x00007ffff6b23af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #5  0x00007ffff6b23d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
 #6  0x0000555556366bf8 in Tokenizer::cppcheckError (this=0x7fffffffc2d0, tok=0x607000006760) at ../lib/tokenize.cpp:8721
 #7  0x000055555636a4bb in Tokenizer::validate (this=0x7fffffffc2d0) at ../lib/tokenize.cpp:9154
 #8  0x000055555633e3aa in Tokenizer::simplifyTokenList1 (this=0x7fffffffc2d0, FileName=0x603000002d50 "test.cpp") at ../lib/tokenize.cpp:4477
 #9  0x00005555563223ca in Tokenizer::simplifyTokens1 (this=0x7fffffffc2d0, configuration="") at ../lib/tokenize.cpp:2286
 #10 0x00005555563235c8 in Tokenizer::tokenize (this=0x7fffffffc2d0, code=..., FileName=0x555556fda9a0 "test.cpp", configuration="") at ../lib/tokenize.cpp:2345
 #11 0x00005555569410ea in TestSimplifyTypedef::tok[abi:cxx11](char const*, bool, cppcheck::Platform::PlatformType, bool) (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>,
     code=0x7fffffffcb70 "class c {\n  typedef char foo[4];\n  foo _a;\n  constexpr operator foo &() const noexcept { return _a; }\n};", simplify=false, type=cppcheck::Platform::Native, debugwarnings=true) at ../test/testsimplifytypedef.cpp:192
 #12 0x000055555697239e in TestSimplifyTypedef::simplifyTypedef129 (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>) at ../test/testsimplifytypedef.cpp:2599
 #13 0x000055555694092c in TestSimplifyTypedef::run (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>) at ../test/testsimplifytypedef.cpp:167
 #14 0x00005555569cab84 in TestFixture::run (this=0x555557728580 <(anonymous namespace)::instance_TestSimplifyTypedef>, str="simplifyTypedef129") at ../test/testsuite.cpp:306
 #15 0x00005555569cb445 in TestFixture::runTests (args=...) at ../test/testsuite.cpp:329
 #16 0x000055555687bdfb in main (argc=2, argv=0x7fffffffd988) at ../test/testrunner.cpp:44
```

* Replace some ASSERT_EQUALS with TODO_ASSERT_EQUALS when the actual result is still wrong

* Remove invalid code from simplifyTypedef129

* Properly skip parentheses
2019-10-12 11:46:00 +02:00
IOBYTE f99e83ece0 Fix #9411 (new daca crash related to using namespace) (#2264) 2019-10-12 11:39:14 +02:00
IOBYTE c98732dd8b fix using type aliases in out of class destructors (#2250) 2019-10-08 19:30:41 +02:00
Steve Mokris 506a952ad2 Parse `extern "C"`, and use it to avoid FP reference warnings (#2234)
Previously, cppcheck discarded the `extern "C"` specifier.  This patch modifies cppcheck to parse each as a Scope in the symbol database, then uses that scope to avoid false positives when making recommendations about changing a function argument to be a reference (since variable references is a C++ feature, unavailable in C, and thus unavailable in `extern "C"`).
2019-10-08 17:48:09 +02:00
IOBYTE 78b9fd9bb9 Fix #9383 ("debug: Function::addArguments found argument 'x' with varid 0." with variadic templates) (#2238) 2019-10-06 12:45:42 +02:00
IOBYTE 46f3f58e5f Fix #9388 ("debug: Executable scope 'x' with unknown function." with alias used in initialization list) (#2239) 2019-10-05 09:34:37 +02:00