Commit Graph

10780 Commits

Author SHA1 Message Date
Daniel Marjamäki f6527fcd9b fixed tests, unused templates are removed by default 2019-05-05 19:40:58 +02:00
Daniel Marjamäki c997186794 Only check unused templates if that is configured 2019-05-05 14:40:30 +02:00
Daniel Marjamäki 7efcb3cfe3 astyle formatting
[ci skip]
2019-05-05 11:41:29 +02:00
Paul Fultz II 8c03be3212 Fix issue 9077: False positive: Returning pointer to local variable (#1821)
* Avoid implicit conversion for lifetimes

* Fix issue 9077

* Add more tests

* Rename function

* Fix implicit conversion with containers

* Format

* Fix crash
2019-05-05 11:40:59 +02:00
Daniel Marjamäki fe04c15c9e CheckStl: Modernize the recommendations. string::starts_with is more intuitive than string::compare 2019-05-05 10:35:44 +02:00
Paul Fultz II a688df0ea1 Fix issue 9120: crash in valueflow (#1822) 2019-05-05 09:51:36 +02:00
Daniel Marjamäki 0b3342abe5 Fix Cppcheck warning 2019-05-04 20:41:43 +02:00
Daniel Marjamäki 45a343ac2d Fixed #8795 (Syntax Error: AST broken, binary operator '||' doesn't have two operands) 2019-05-04 19:05:03 +02:00
Daniel Marjamäki d1bb0465b8 Fixed 2 Cppcheck warnings 2019-05-04 11:58:03 +02:00
Daniel Marjamäki 604a13a22b rename parameter 2019-05-04 10:36:49 +02:00
Paul Fultz II 091f4bcf8d Add check for unnecessary search before insertion
This will warn for cases where searching in an associative container happens before insertion, like this:

```cpp
void f1(std::set<unsigned>& s, unsigned x) {
    if (s.find(x) == s.end()) {
        s.insert(x);
    }
}

void f2(std::map<unsigned, unsigned>& m, unsigned x) {
    if (m.find(x) == m.end()) {
        m.emplace(x, 1);
    } else {
        m[x] = 1;
    }
}
```

In the case of the map it could be written as `m[x] = 1` as it will create the key if it doesnt exist, so the extra search is not necessary.

I have this marked as `performance` as it is mostly concerning performance, but there could be a copy-paste error possibly, although I dont think thats common.
2019-05-02 11:04:23 +02:00
Rikard Falkeborn 4edc248dae Fix 8840: Don't warn when returning a bitmask as bool (#1818)
A common pattern is to have a function like similar to this:

	bool isFlagSet(uint32_t f) {
		return f & 0x4;
	}

Warning that the function returns a non-boolean in this case is too
noisy, it would be better suited for a Misra check, so remove the
warnings in the most obvious cases.
2019-05-02 07:00:27 +02:00
Daniel Marjamäki 6c3c090403 Fixed #6317 (wrong simplification: int i = 1.5; return i; get simplified to: return 1.5;) 2019-05-01 17:05:16 +02:00
Rikard Falkeborn 1cc5f3abe7 Set wchar_t type (#1807)
This is necessary for valueflow to know the size, for example when
calculating sizeof(wchar_t).
2019-05-01 16:34:28 +02:00
Daniel Marjamäki 6da42a3d63 Fixed #9112 (false positive: (error) Array index out of bounds; buffer 'x' is accessed at offset n.) 2019-05-01 13:00:14 +02:00
Daniel Marjamäki b3a46e72dc Fix and test syntaxError suppression 2019-05-01 11:54:13 +02:00
Paul Fultz II 71bd7f68d4 Fix bug in lifetime constructors (#1816) 2019-05-01 07:52:52 +02:00
Daniel Marjamäki 66064fb2bb Disable valueFlowGlobalConstVar until #9099 is fixed 2019-04-30 20:51:59 +02:00
Daniel Marjamäki 1d12136b59 Fixed Cppcheck uninitStructMember warnings 2019-04-30 20:45:48 +02:00
Daniel Marjamäki 41cf13bb7e Fixed #error in self check when __CPPCHECK__ is defined 2019-04-30 20:31:46 +02:00
Daniel Marjamäki d69f002757 Fixed Cppcheck shadowVar warning 2019-04-30 20:19:21 +02:00
Rikard Falkeborn c7d7f8738c Optimize astStringVerbose() for large arrays (#1815)
Change the astStringVerbose() recursion to extend a string instead of
returning one. This has the benefit that for tokens where the recursion
runs deep (typically large arrays), the time savings can be substantial
(see comments on benchmarks further down).

The reason is that previously, for each token, the astString of its
operands was constructed, and then appended to this tokens astString.
This led to a lot of unnecessary string copying (and with that
allocations). Instead, by passing the string by reference, the number
of temporary strings is greatly reduced.

Another way of seeing it is that previously, the string was constructed
from end to beginning, but now it is constructed from the beginning to
end. There was no notable speedup by preallocating the entire string
using string::reserve() (at least not on Linux).

To benchmark, the changes and master were tested on Linux using the
commands:

	make
	time cppcheck --debug --verbose $file >/dev/null

i.e., the cppcheck binary was compiled with the settings in the
Makefile. Printing the output to screen or file will of course take
longer time.

In Trac ticket #8355 which triggered this change, an example file from the
Wine repository was attached. Running the above cppcheck on master took
24 minutes and with the changes in this commmit, took 22 seconds.

Another test made was on lib/tokenlist.cpp in the cppcheck repo, which is
more "normal" file. On that file there was no measurable time difference.

A synthetic benchmark was generated to illustrate the effects on dumping
the ast for arrays of different sizes. The generate code looked as
follows:

	const int array[] = {...};

with different number of elements. The results are as follows (times are
in seconds):

	N	master optimized
	10	0.1    0.1
	100	0.1    0.1
	1000	2.8    0.7
	2000	19     1.8
	3000	53     3.8
	5000	350    10
	10000	3215   38

As we can see, for small arrays, there is no time difference, but for
large arrays the time savings are substantial.
2019-04-30 13:35:48 +02:00
IOBYTE 505b7f7ebd Fixed #9110 (Syntax error on valid C++ code) (#1813) 2019-04-29 15:17:37 +02:00
Paul Fultz II ae8a3aae8d Fix FP with unused variable (#1814) 2019-04-29 11:50:19 +02:00
Daniel Marjamäki 2e694f38c8 Refactoring; Use const reference instead of const 2019-04-29 08:53:36 +02:00
Daniel Marjamäki 45e5edce16 Fixed Cppcheck shadowVariable warning 2019-04-28 12:04:44 +02:00
Daniel Marjamäki 74fad6ce05 Modernizing; Use std::accumulate instead of for loop 2019-04-28 11:25:43 +02:00
Daniel Marjamäki 9c5d24c551 Modernizing: Use std::accumulate instead of for loop 2019-04-28 11:17:11 +02:00
Daniel Marjamäki 9d72e24edb Refactoring; Use stl algorithm instead of for loop 2019-04-28 10:30:20 +02:00
Daniel Marjamäki f503386666 Refactoring; replace for loop with std::find_if 2019-04-28 10:07:11 +02:00
Daniel Marjamäki aaf1af6736 Fix Cppcheck passedByValue warning 2019-04-28 07:58:47 +02:00
Daniel Marjamäki fd4e371091 Refactoring: Use stl algorithm 2019-04-28 07:40:00 +02:00
Daniel Marjamäki 69faa0d8c8 Refactoring: Use STL algorithms 2019-04-28 07:30:17 +02:00
Daniel Marjamäki 004d7d5333 Fixed #8580 (False positive: unused function (lambda)) 2019-04-27 17:17:51 +02:00
Daniel Marjamäki 6fcef867a1 Refactoring; use range for loops 2019-04-27 17:04:14 +02:00
Paul Fultz II c4325bbec3 Fix issue 9103: False positive duplicateConditionAssign (#1808)
* Fix issue 9103: False positive duplicateConditionAssign

* Update conditional message
2019-04-26 12:30:41 +02:00
Paul Fultz II e856920488 Fix false positive with ignoredReturnValue with std::move (#1809) 2019-04-26 12:22:31 +02:00
Daniel Marjamäki b1ca7c9a66 astyle formatting
[ci skip]
2019-04-26 11:30:35 +02:00
Paul Fultz II 39f4374446 Improve diagnostics with null smart pointers (#1805)
* Warn when dereferencing null smart pointers

* Improve tracking of smart pointer values

* Use library isSmartPointer
2019-04-26 11:30:09 +02:00
Daniel Marjamäki 76e13c45c7 temporarily disable duplicateConditionalAssign 2019-04-25 07:44:19 +02:00
Daniel Marjamäki da46bff1b3 CheckLeakAutoVar: Use Library::isSmartPointer() 2019-04-24 15:35:47 +02:00
Daniel Marjamäki 2513c1499b Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
Nicodemes 272760f9ca Fix explicit constructor with default arguments check bug
Before this fix, the code:
```
class A {
    A(int, int x=3){
        x;
    }
};
```
Was considered OK.
But explicit keyword is still needed

I'm still new to open-source contributions, so I will gladly take advice.
2019-04-23 10:46:22 +02:00
Frank Zingsheim 315a093e18 CMake: Find header in externals, e.g. externals/picojson.h 2019-04-22 18:52:02 +02:00
Daniel Marjamäki 80d7df01cd Fixed #8848 (False positive memory leak if locally defined type returns a new pointer) 2019-04-22 17:37:41 +02:00
Daniel Marjamäki 0edf0b5628 Fixed #8938 (FP identicalInnerCondition) 2019-04-22 16:54:59 +02:00
Gary Leutheuser bca2dfb3f4 Implement #7597 - valueflow: global constant (#1802)
* Implement const global value flow

* Tabs to spaces
2019-04-21 06:54:32 +02:00
IOBYTE e786c6b7d4 partial fix for #8663 (Stack overflow with template disambiguator) (#1801)
This fixes simplifyUsing to remove 'typename' and 'template' from type
aliases of the form: using T3 = typename T1::template T3<T2>;

This lets the template simplifier instantiate the type alias which will
then remove the using type alias.

The crash will still happen if there is no instantiation because the
type alias will not be removed.  The type alias is what cppcheck is
crashing on after the template simplifier and that still needs fixing.
2019-04-21 06:46:16 +02:00
Daniel Marjamäki ece13033b2 dmake: use -isystem for externals to avoid compiler warnings 2019-04-19 14:52:49 +02:00
amai2012 28bc3cad92 #8913 SIGSEGV in CheckUnusedVar::checkFunctionVariableUsage - C++/CLI code 2019-04-19 13:55:25 +02:00
IOBYTE 7799ed4243 Fixed #8889 (varid on function when using trailing return type.) (#1800)
* Fixed #8889 (varid on function when using trailing return type.)

Don't set varid for trailing return type.

* Add a test for #9066 (Tokenizer::setVarId: varid set for trailing return type)
2019-04-18 20:22:39 +02:00
Daniel Marjamäki 648acd1cbf astyle formatting
[ci skip]
2019-04-18 20:21:00 +02:00
Paul Fultz II 103002578d Add check for duplicate condition and assignment (#1799)
* Add check duplicate condition and expression

* Format

* Add assign token

* Add to classInfo

* Change note messages
2019-04-18 20:20:24 +02:00
Daniel Marjamäki f26b15e5b5 astyle formatting
[ci skip]
2019-04-16 19:07:44 +02:00
Daniel Marjamäki 253f2c9e9d Fixed #9043 (false positive & regression: Variable '*s' is reassigned a value before the old one has been used.) 2019-04-16 19:07:26 +02:00
bbennetts 7287ffe781 Handle 'arguments' sections in compile_commands.json (#1797)
* Handle 'arguments' sections in compile_commands.json

Previous code assumes 'commands' exists and ill assert if t does not.

* Correct typo checking for "arguments" rather than "commands"

* Use ostringstring rather than stringstream

* Add test deominstrating graceful degradation

* Add test for parsing "arguments" rather than "commands"
2019-04-15 20:03:42 +02:00
Daniel Marjamäki 83f8d7fab9 test/cli: Improved proj2 testing. fixed bug for relative path when vs-solution is imported with relative path 2019-04-15 19:00:57 +02:00
Daniel Marjamäki 15eba39963 test/cli: better handling of absolute ignored paths 2019-04-15 08:48:58 +02:00
Paul Fultz II a90caa7e5a Fix issue 9006: False positive: Return value of function std::move() is not used.
This is trying to fix the issue by fixing the ast and symbol database. First, the ast nodes will be created for the init list and the symbol database will not mark it as a scope. I am not sure if this is the correct approach as I dont really understand how the AST part works.

It did change the AST for `try {} catch (...) {}` but that is because it incorrectly treats `try {}` as an initializer list.
2019-04-15 06:37:27 +02:00
Daniel Marjamäki a18025c95d test/cli: tweaks for running it in windows 2019-04-14 15:53:32 +02:00
Daniel Marjamäki b94f4176f1 test/cli: execute addon 2019-04-14 15:00:03 +02:00
Daniel Marjamäki 0cc2b5ca14 Fix wrong assignment 2019-04-14 07:27:23 +02:00
Daniel Marjamäki a0dd853642 analyzing one vs config (first debug config that matches platform) 2019-04-13 20:01:40 +02:00
Daniel Marjamäki d3e7d09f5c Refactoring; Reorder Settings members alphabetically. 2019-04-13 15:34:50 +02:00
Daniel Marjamäki b1b5b27b4e addons: write column in error message(s) 2019-04-13 10:22:13 +02:00
Daniel Marjamäki 1393c1c3a0 AST: Try to handle C++17 syntax 'if (init;expr)' 2019-04-12 17:35:06 +02:00
Daniel Marjamäki b04d1815ed Add -std=c++17 and allow semicolon in 'if ()' 2019-04-12 09:10:25 +02:00
Daniel Marjamäki cb06aebdab Removed --std=posix. From now on, if you use --library=posix then the posix checks will be enabled. 2019-04-12 06:47:28 +02:00
Daniel Marjamäki dfe417c369 msvc compatibility: /constexpr/const/ 2019-04-11 21:06:37 +02:00
Daniel Marjamäki c9172b169a Improved handling of paths when importing cppcheck gui project 2019-04-11 21:02:49 +02:00
Daniel Marjamäki 7ede0feb2c Better handling for excluded paths 2019-04-11 18:46:57 +02:00
Daniel Marjamäki f6f8e2c192 Travis: Try to make travis happy by temporary setting checkUnusedTemplates to true 2019-04-10 20:27:24 +02:00
Daniel Marjamäki e27b54664e appveyor: /constexpr/const/ 2019-04-10 19:15:56 +02:00
Daniel Marjamäki 2015f25a84 addon: Fix parsing of addon output 2019-04-10 18:28:46 +02:00
Daniel Marjamäki 42fdb1f826 ImportProject: checkHeaders, checkUnusedTemplates, maxCtuDepth 2019-04-10 17:04:18 +02:00
Daniel Marjamäki f6b410b469 GUI: add setting for 'checkHeaders', 'checkUnusedTemplates' and 'maxCtuDepth' to project 2019-04-10 16:49:24 +02:00
IOBYTE 3094026e59 template simplifier: fix cppcheck warnings (#1793) 2019-04-09 20:07:13 +02:00
orbitcowboy e47b6bf862 Revert quick fix: 0ace50204b (comments) 2019-04-09 08:38:08 +02:00
Daniel Marjamäki cf6f886a68 Addons: try to create dump file in cppcheck build dir 2019-04-09 07:05:41 +02:00
Daniel Marjamäki 1f68e038be Addons: Describe running addons from cppcheck in the manual 2019-04-08 21:31:38 +02:00
Daniel Marjamäki 44dcbda88e Addons: Fixed handling of addon configuration 2019-04-08 19:42:16 +02:00
Daniel Marjamäki 7610513c49 Fixed #9090 (Do not simplify standard functions) 2019-04-08 19:00:46 +02:00
Daniel Marjamäki 4bb06eceeb astyle formatting
[ci skip]
2019-04-08 18:53:14 +02:00
Márton Csordás ca3c59fa6f Add missing line feed to the generated plist output (#1792)
Add missing line feed to the generated plist output because DOS
uses carriage return and line feed as a line ending.
2019-04-08 18:09:18 +02:00
Daniel Marjamäki 50a5763cf5 Addons: Make it possible to configure any addon with json 2019-04-08 18:07:23 +02:00
Daniel Marjamäki a508b2abfd Addons: Add same handling in Windows as in Linux 2019-04-07 19:53:34 +02:00
Daniel Marjamäki bf9006737a Addons: Adding support in Cppcheck CLI to execute addons 2019-04-07 17:01:59 +02:00
orbitcowboy 64f0744242 Merge branch 'master' of https://github.com/danmar/cppcheck 2019-04-07 13:27:47 +02:00
orbitcowboy 0ace50204b Fixed a crash on garbage code. The test input was found by afl_cppcheck (type2). Unforunately, the cppcheck-fuzzer-client was crashing only when executing the binary input from afl-fuzz. Using the translated-input (C-code) did not lead to crash. I tested it with activated address/undefined behaviour sanitizer as well as non-instrumented source code. Since the translated output is too long (164 lines), i will not add it the testgarbage.cpp. 2019-04-07 13:27:33 +02:00
Daniel Marjamäki 6d7ec98dd6 Import Project: import suppressions from gui project 2019-04-07 13:15:25 +02:00
Daniel Marjamäki 111db91387 ImportProject: Import excluded paths properly 2019-04-07 12:31:52 +02:00
Daniel Marjamäki 3701db96a3 Refactoring; use range for loop 2019-04-07 11:58:42 +02:00
Daniel Marjamäki 83106d5827 Unused templates: Remove unused template function with variadic arguments 2019-04-07 08:37:04 +02:00
Rikard Falkeborn 82a1e3c61c CheckInternal: Extend redundant null pointer check before Token::Match() (#1789)
Improve the internal check for redundant null pointer check before
calling Token::Match() (and friends). Now, warn about code snippets like

    if (a && tok && Token::Match(tok, "foo"))

Also, extend the check for the inverted case.

There is still no warning for

    if (tok && a && Token::Match(tok, "foo"))

since that would require checking if a is independent of tok.
2019-04-06 07:44:44 +02:00
Rikard Falkeborn d23e987941 Fix CheckInternal warnings (#1790) 2019-04-06 06:55:46 +02:00
Rikard Falkeborn 295153df72 Checkstring fixes (#1783)
* teststring.cpp: Fix ternary syntax in tests

* stringLiteralWrite: Add tests wide character and utf16 strings

* suspiciousStringCompare: Add test with wide character string

* strPlusChar: Handle wide characters

* incorrectStringCompare: Add test with wide string

* Suspicious string compare: suggest wcscmp for wide strings

* deadStrcmp: Extend to handle wide strings

* sprintfOverlappingData: Print name of strcmp function

* Conversion of char literal to boolean, add wide character tests

* Conversion of char literal to boolean, fix ternary
2019-04-06 06:54:38 +02:00
Oliver Stöneberg 16ebb90b32 library.cpp: optimized Library::detectContainer() (#1778)
* library.cpp: optimized Library::detectContainer()

reduces Ir from 5882 to 1149 according to callgrind

* fixed hang in tests
2019-04-06 06:42:01 +02:00
IOBYTE 5cdde701ba template simplifier: add minimal template template support (#1779) 2019-04-04 06:07:49 +02:00
Daniel Marjamäki de4f57ec0f Buffer overflow: Add CTU checking for pointer arithmetic overflows 2019-04-03 06:43:56 +02:00
IOBYTE 9f3ecdde31 Fixed #9076 (Template Simplifier : template < template <typename> T >) (#1777)
This does not add support for template templates.  It only skips the
template template parameter.
2019-04-03 06:02:38 +02:00
Daniel Marjamäki 3f9dd4c567 Variable scope: Fix FP for reference variable in range for loop 2019-04-02 12:59:24 +02:00
IOBYTE f5cb289b7d template simplifier: fix another crash (#1774)
This fixes a daca crash in Vc-1.3.3/tests/casts.cpp.
2019-04-02 09:00:11 +02:00
Daniel Marjamäki 761f18c75c Fixed #8988 (False positive: using memset on struct) 2019-04-01 19:32:03 +02:00
IOBYTE 165cce5dcc template simplifier: fix some crashes (#1772)
Fix some crashes caused by the template simplifier generating bad code
for some instantiations.

Sorry but there are no tests because I was unable to get C-Reduce to
create examples that were not garbage code.
2019-04-01 08:04:47 +02:00
Daniel Marjamäki 0368648aff debug warnings; report missing type for auto tokens 2019-03-31 17:38:00 +02:00
Daniel Marjamäki fbc769266c Fixed #9060 (TemplateSimplifier::templateParameters : var <...>) 2019-03-31 16:29:28 +02:00
Daniel Marjamäki 0efddc4010 astyle formatting
[ci skip]
2019-03-31 16:20:06 +02:00
Daniel Marjamäki 29a5404d1e Incomplete statement: Fix FP for 'ar & x' 2019-03-31 11:50:57 +02:00
Daniel Marjamäki 73433c2961 Syntax error: Clarify a syntax error in audacity 2019-03-31 10:46:59 +02:00
Daniel Marjamäki b30d463baf Fix wrong syntax error 2019-03-31 09:34:19 +02:00
Daniel Marjamäki c5807459f9 CheckBufferOverrun: Add check for pointer arithmetics 2019-03-31 09:00:52 +02:00
Daniel Marjamäki 51b64191e5 Fixed slow checking in FwdAnalysis
Credit to OSS-Fuzz for reporting this!
2019-03-30 14:22:24 +01:00
Daniel Marjamäki b0c58f2b10 Fixed #9000 (SymbolDatabase: lambda scope) 2019-03-30 10:32:36 +01:00
Daniel Marjamäki fe285f1df3 Fixed #9055 (SymbolDatabase: second argument is missing in the symbol database) 2019-03-30 07:44:36 +01:00
IOBYTE d88ee2d6a2 Fixed #9070 (Segmentation fault in TemplateSimplifier::simplifyTemplateAliases (scram package)) (#1771)
This only fixes the crash.  It does not fix the underlying problem of
template using with templates of templates causing the use of deleted
instantiations.
2019-03-30 06:53:17 +01:00
Sebastian d233b56d58
Fix #9079 (make checkcfg crashes on Linux) (#1769)
temp.bufferSizeArg2 was not initialized when only bufferSizeArg1
was specified or the value was out of range. But in valueflow.cpp in
valueFlowDynamicBufferSize() it was used as if it is always initialized
and has a sane value (greater than 0).
2019-03-30 05:58:23 +01:00
Daniel Marjamäki b5a285319c Fixed #9073 (Segmentation fault in Token::isUnaryOp() with ode) 2019-03-29 19:37:23 +01:00
Daniel Marjamäki 54bea2847a STL: Better out of bounds checking for empty containers when index is unknown 2019-03-29 15:20:17 +01:00
Daniel Marjamäki 3c30d274a0 Clarify STL out of bounds warning message 2019-03-29 11:13:25 +01:00
Daniel Marjamäki e88a0c00c1 Fixed #9039 (STL: array index out of bounds: str.begin() + 1) 2019-03-28 12:49:52 +01:00
IOBYTE 22f01f035c Fixed #9042 (Another `using BOOL` type breach) (#1765) 2019-03-27 21:42:50 +01:00
Daniel Marjamäki 0f6a90c595 Fixed #9069 (crash on invalid code: ' x= y{ } name5 ')
Credit to OSS-Fuzz for reporting this!
2019-03-27 18:17:11 +01:00
Daniel Marjamäki 4a45655bc2 astyle formatting
[ci skip]
2019-03-27 18:15:12 +01:00
Frank Zingsheim 574b77cf1f Fixed: FP return reference to thread_local variable (#1758) 2019-03-27 12:22:53 +01:00
Oliver Stöneberg 88dc74929a Add defines set by compiler options when using compilation database (#1763)
* Add defines set by compiler options when using compilation database

sets __cplusplus and __STDC_VERSION__ based on -std and the defines for -municode, -fpie, -fPIE, -fpic and -fPIC

* Fixed merge
2019-03-27 10:23:04 +01:00
Daniel Marjamäki c77f31319d Fix crash when checking re2c textfile 2019-03-26 20:51:41 +01:00
Daniel Marjamäki 7c6f21a158 astyle formatting 2019-03-26 20:51:04 +01:00
Daniel Marjamäki c262aeffdd Fixed #9068 (crash on invalid code) 2019-03-26 19:57:32 +01:00
firewave ce11778a20 fixed parsing of -std= in compilation database 2019-03-26 19:02:08 +01:00
Sebastian 29815b2dd8
Fix #8922 (SIGSEGV below exprDependsOnThis - stack overflow?) (#1761)
This limits the recursion depth as a last line of defense to avoid stack
overflows when there are really huge arrays.
See https://trac.cppcheck.net/ticket/8922
2019-03-26 18:57:01 +01:00
Daniel Marjamäki 15676612c0 Fixed #9034 (crash on reading invalid code: '> typedef') 2019-03-26 16:14:24 +01:00
IOBYTE 5b72e1f568 Fixed #9040 (Type alias 'BOOL' declared with 'using' keyword breaks type detection) (#1759)
Moved simplifyUsing from TemplateSimplifier to Tokenizer.
2019-03-26 07:09:56 +01:00
Daniel Marjamäki 49e2f9d551 Fixed #9063 (Crash on invalid code: x='0' ++ '0' ( return)[ ];) 2019-03-25 15:29:23 +01:00
IOBYTE 10fcf731d9 Fixed #9021 (template simplifier: crash in simplifyCalculations) (#1757) 2019-03-25 14:56:51 +01:00
IOBYTE b6faa11fbf Fixed #9056 ("using namespace" inside namespace causes "SymbolDatabase bailout;) (#1753)
Fixed the bailout warning and one of the varid bugs.

The trailing return type still has a varid.
2019-03-24 17:31:34 +01:00
Daniel Marjamäki 7995b2fb86 getArguments: Avoid too deep recursion in array initialization 2019-03-24 11:51:28 +01:00
Daniel Marjamäki e0f1418228 Fixed #9034 (Tokenizer::setVarId: function call parameter is not variable declaration) 2019-03-24 07:06:21 +01:00
Daniel Marjamäki 18aa968a7a Astyle formatting 2019-03-23 19:03:57 +01:00
Daniel Marjamäki 5126e4b1af Try to fix Visual Studio compiler error 2019-03-23 19:02:05 +01:00
Daniel Marjamäki 418eb43d45 Fixed #9032 (False-positive detection of reassigned value before used for pointer parameter) 2019-03-23 19:01:02 +01:00
Daniel Marjamäki d82c792c1b astyle formatting 2019-03-23 19:00:03 +01:00
Daniel Marjamäki a9082c902a Fixed #9058 (crash on invalid code in FwdAnalysis::checkRecursive) 2019-03-23 18:27:41 +01:00
Daniel Marjamäki d6b806c592 CheckBufferOverrun: Better CTU checking when variable address is passed 2019-03-23 15:57:17 +01:00
Daniel Marjamäki d27a4ad82e CheckBufferOverrun: Fix ctu checking 2019-03-23 15:26:13 +01:00
Daniel Marjamäki 9653760547 CheckBufferOverrun: Improved CTU analysis for array 2019-03-23 11:20:35 +01:00
IOBYTE 40af889df0 Fixed #9053 (simplifyTypedef: wrong simplification of '(const d)' when 'd' is a array) (#1751)
* Fixed #9053 (simplifyTypedef: wrong simplification of '(const d)' when 'd' is a array)

* fix whitespace
2019-03-23 10:45:38 +01:00
Pavol Misik 7c7ee66cf9 Fix crash in TemplateSimplifier::TokenAndName::TokenAndName in case of template constexpr (#1748)
This is not propper solution. This change just eliminates crash and logs error.

https://trac.cppcheck.net/ticket/9046
2019-03-23 10:42:41 +01:00
Daniel Marjamäki a135683d2f Refactoring; Renamed CWE786 and CWE788 2019-03-23 08:41:20 +01:00
Daniel Marjamäki 15fc9a622d CheckBufferOverrun: Add CTU analysis 2019-03-23 08:36:10 +01:00
Paul Fultz II 91138578cc Fix 9052: Crash: SIGSEGV in Token::previous (this=0x0) while checking mariadb-10.0 2019-03-22 01:56:09 +01:00
Daniel Marjamäki 55433fce40 Library: added bufferSize parameters 2019-03-20 19:26:57 +01:00
Daniel Marjamäki 14528bcf25 Library: allowed values for the buffer-size attribute: malloc/calloc/strdup 2019-03-20 06:46:55 +01:00
Daniel Marjamäki 031362ae01 CheckBufferOverrun: Fix false positive 2019-03-19 21:07:08 +01:00
Daniel Marjamäki 6cbe818f1a Fix uninitialized variable usage 2019-03-19 13:17:27 +01:00
Daniel Marjamäki a0e58f0039 Revert "Revert "CheckBufferOverrun: Handle multidimensional arrays""
This reverts commit 9d1755f449.
2019-03-19 13:16:22 +01:00
Daniel Marjamäki 9d1755f449 Revert "CheckBufferOverrun: Handle multidimensional arrays"
This reverts commit e98a4a6f14.
2019-03-19 13:13:29 +01:00
Daniel Marjamäki e98a4a6f14 CheckBufferOverrun: Handle multidimensional arrays 2019-03-19 09:29:32 +01:00
Paul Fultz II 774464eabb Fix issue 8996: False positive duplicateCondition
This fixes issue 8996 by improving the alias checking by using lifetime analysis. It also extends the lifetime checker to handle constructors and initializer lists for containers and arrays.
2019-03-19 06:25:10 +01:00
Rikard Falkeborn 794f65bac1 Handle prefixed strings and characters in Token (#1742)
This makes it possible to call getStrLength() and similar functions
before the tokenizer is called.
2019-03-18 06:18:25 +01:00
Daniel Marjamäki b53a2e5dc4 CheckBufferOverrun: restore minsize code 2019-03-17 20:34:49 +01:00
Daniel Marjamäki 03f8535c71 Better multiline warning when there is buffer overflow 2019-03-17 20:12:02 +01:00
Daniel Marjamäki 3c85d8a8ac ValueFlow: Better info for buffer size values 2019-03-17 19:02:36 +01:00
Sebastian 19e9e42dd7
Library: Enhance minsize configuration and allow simple values. (#1736)
Some POSIX and Windows functions require buffers of at least some
specific size. This is now possible to configure via for example this
minsize configuration: `<minsize type="value" value="26"/>`.
The range for valid buffer size values is 1 to LLONG_MAX
(9223372036854775807)
2019-03-17 14:22:26 +01:00
Daniel Marjamäki 0771929518 Buffer overflow: Handling of dynamically allocated buffer 2019-03-17 13:40:56 +01:00
Daniel Marjamäki 92f4113b59 Array index: Checking array index out of bounds for dynamic buffers 2019-03-17 13:09:15 +01:00
Daniel Marjamäki 18668a52b9 Library: Added buffer-size attribute for <alloc> 2019-03-17 10:55:15 +01:00
Daniel Marjamäki a3257349b9 astyle formatting
[ci skip]
2019-03-17 10:50:06 +01:00
Daniel Marjamäki c7155a8e08 Removed '--experimental-fast' flag 2019-03-17 08:19:56 +01:00
Daniel Marjamäki b0c92c1ac1 CheckNullPointer: Use library instead of hardcoding 2019-03-17 07:37:38 +01:00
Daniel Marjamäki 87fe5c060e Refactoring of Null Pointer Checker 2019-03-16 21:21:30 +01:00
Daniel Marjamäki d0c1632b51 Fix CheckBufferOverrun::array_index_12 when compiling with VS 2019-03-16 19:41:13 +01:00
Daniel Marjamäki 3dc34f1515 Disable all simplified checks 2019-03-16 09:17:50 +01:00
Daniel Marjamäki 0e88a17aca CheckInternal: Use 'normal' checking 2019-03-16 08:51:33 +01:00
Daniel Marjamäki f40a80c349 Use 'normal' checking instead of 'simplified' 2019-03-16 07:19:48 +01:00
Daniel Marjamäki a2a216bbe3 SymbolDatabase: Improved handling of 'normal' non simplified token list 2019-03-15 19:00:42 +01:00
Daniel Marjamäki 92485245ce Restore severity for 'autoVariables' 2019-03-15 15:13:11 +01:00
Sebastian 08d41ab8af
Load std.cfg before all other libraries (#1740)
- CLI: Save the libraries that should be loaded to a list and load them
after the std.cfg has been loaded.
- GUI: Load std.cfg (and windows.cfg / posix.cfg when applicable) before
setting other options and loading the other libraries.
In the project-file-dialog the std.cfg is searched first. If some
other library fails to load is is retried with first loading std.cfg.
- boost.cfg: Enable containers that depend on std containers.
2019-03-15 06:59:37 +01:00
Paul Fultz II 3615eac347 Move useStlAlgorithm to normal checking (#1741) 2019-03-15 06:15:56 +01:00
Daniel Marjamäki a1ade2dd7d Refactoring: Use range for 2019-03-14 19:57:58 +01:00
Daniel Marjamäki 56c47fc6ed Refactoring: use continue 2019-03-14 19:53:45 +01:00
Daniel Marjamäki 3656f1ae4f Auto variables: Fix false negatives for normal tokens 2019-03-14 13:51:35 +01:00
Daniel Marjamäki 6eeee743d2 Auto variables: Minor cleanup 2019-03-14 06:41:11 +01:00
Daniel Marjamäki b984897526 ValueFlow: Fix sizeof for array of library type 2019-03-13 18:31:41 +01:00
Daniel Marjamäki 2ecfae0a98 CheckBufferOverrun: the bufferNotZeroTerminated did not work well, hide that for now 2019-03-13 06:45:01 +01:00
Daniel Marjamäki 81a1d744c6 CheckBufferOverrun: fix FP for array definition of static class member 2019-03-13 06:39:09 +01:00
Daniel Marjamäki 67e8b99c2c CheckBufferOverrun: Readd a check for strncpy/memcpy/etc 2019-03-12 21:15:26 +01:00
Daniel Marjamäki 2a00667609 CheckBufferOverrun: cleanup 2019-03-12 18:58:14 +01:00
Daniel Marjamäki 11e32ff445 ValueFlow: Handle compound assignments in execute() 2019-03-12 18:53:58 +01:00
Daniel Marjamäki 0c08f6db6c CheckBufferOverrun: Use AST to lookup array 2019-03-12 06:46:38 +01:00
Daniel Marjamäki 4ababeb704 Fix 'make checkcfg' 2019-03-11 21:39:39 +01:00
Daniel Marjamäki ea23033a65 Array index out of bounds: Fix false positive 2019-03-11 20:33:08 +01:00
Daniel Marjamäki 7b17b33a49 ValueFlow: fix handling of sizeof(*p) 2019-03-11 20:32:24 +01:00
Daniel Marjamäki 17253cdb55 buffer overflow: Fix false positive 2019-03-11 19:40:17 +01:00
Daniel Marjamäki bd048085bd Add CheckBufferOverrun::arrayIndexThenCheck 2019-03-11 19:20:06 +01:00
Daniel Marjamäki a933261e14 Add message id arrayIndexOutOfBoundsCond 2019-03-11 19:12:03 +01:00
orbitcowboy 0721c9f7f0 Running astyle [ci skip]. 2019-03-11 15:32:30 +01:00
Daniel Marjamäki 729f57d8f1 Start a major rewrite of CheckBufferOverrun. For now only the 'array index' and 'buffer overflow' checks are rewritten.
There are important TODOs still; for instance adding CTU support using our CTU infrastructure, add handling of pointers (maybe I'll use FwdAnalysis for this), add handling of multidimensional arrays, etc..
2019-03-11 12:34:33 +01:00
Daniel Marjamäki 34711bcb93 Remove unused functions 2019-03-11 12:23:22 +01:00
Daniel Marjamäki df8cfe2fc6 Travis: Fix Cppcheck warning 2019-03-10 12:24:41 +01:00
Rikard Falkeborn 6a3dd9a185 Handle concatenated string and char literals
This handles concatenated strings and characters from simplecpp.
Previously, L'c' would be preprocessed to the tokens  "L" and "'c'".
cppcheck would then remove the "L" token and set "'c'" to be a wide
character literal. Now, it needs to remove the prefix instead.

When doing this, add handling of utf32 encoded literals (U) and UTF-8
encoded literals (u8).
2019-03-10 10:38:50 +01:00