Daniel Marjamäki
6ca1aba4a7
UninitVar: Fix --experimental-fast issues
2019-02-10 19:00:01 +01:00
Simon Martin
eaaff30e65
Ticket #8878 : Properly simplify typedefs within template instantiations. ( #1656 )
2019-02-10 09:45:33 +01:00
Daniel Marjamäki
4f232e41dd
Add --experimental-fast option
2019-02-09 14:40:50 +01:00
Daniel Marjamäki
502d5e9142
1.87: Set versions
2019-02-09 09:07:27 +01:00
Daniel Marjamäki
9337af8965
astyle formatting
2019-02-09 08:48:10 +01:00
Paul Fultz II
797eccc203
Fix possible out of bounds access on arguments ( #1652 )
...
* Fix possible outbounds access on arguments
* Log a warning when the arguments mismatch
* Format
2019-02-09 08:47:36 +01:00
IOBYTE
155e4ce912
Fixed #8971 ("(debug) Unknown type 'x'." using alias in class members) ( #1653 )
...
* Fixed #8971 ("(debug) Unknown type 'x'." using alias in class members)
* template simplifier: partial fix for #8972
Add support for multi-token default template parameters.
* template simplifier: fix for #8971
Remove typename outside of templates.
2019-02-09 08:34:59 +01:00
Daniel Marjamäki
bd7790fd8c
Update copyright year
2019-02-09 07:24:06 +01:00
Paul Fultz II
d7c20b15e7
Fix FP with const argument when doing a variable and cast ( #1649 )
2019-02-07 14:59:09 +01:00
IOBYTE
7025254c26
Fixed #8969 (syntax error: template) ( #1647 )
...
Fixed template detection to handle multi-token template parameters.
2019-02-07 08:50:49 +01:00
Daniel Marjamäki
14a312e310
useInitializationList: Skip warning when rhs is a multi line lambda. For readability it might be better to have assignments in constructor in this case.
2019-02-05 19:53:10 +01:00
IOBYTE
1faae52d06
Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias) ( #1643 )
...
* Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias)
This commit adds non-template type alias support to the template
simplifier. Only relatively simple type aliases are supported at this
time. More complex types will be added later.
--debug-warnings will show unsupported type aliases.
Type alias support will be removed from the symbol database in the
future. Type alias tests have been removed from the symbol database
tests.
* Add the changes.
* Fix codacy warning.
* Fix travis warnings.
2019-02-05 08:52:23 +01:00
Daniel Marjamäki
b7631b0390
Add more timers in tokenizer
2019-02-04 21:13:59 +01:00
Daniel Marjamäki
23599428cb
Clarify Cppcheck output
2019-02-03 19:49:27 +01:00
Daniel Marjamäki
437800f46d
CLI: Added --max-ctu-depth
2019-02-03 17:51:36 +01:00
Daniel Marjamäki
a4406aca32
Fixed #7845 (Leak reported when ignoring return value of 'new', even if pointer saved by constructor)
2019-02-03 12:15:05 +01:00
Daniel Marjamäki
ae001d4336
Fixed #8957 (Tokenizer::setVarId: varid not set when lambda function is used)
2019-02-03 08:57:04 +01:00
Daniel Marjamäki
4457faa26b
Fixed #8850 (Array in-class initialization for private member considered uninitialized)
2019-02-02 18:34:41 +01:00
Daniel Marjamäki
9d8f798aca
Fixed #8951 (false postive: (style) The class 'x' does not have a constructor although it has private member variables.)
2019-02-02 18:25:26 +01:00
IOBYTE
5c0ec782f1
Add ability to time simplifyTemplates. ( #1640 )
2019-02-01 18:17:18 +01:00
IOBYTE
d08aa666f6
template simplifier: fix crash on windows ( #1639 )
...
* template simplifier: fix crash on windows
Use right token when searching for template type alias to delete.
* template simplifier: fix a cppcheck warning
2019-02-01 06:59:49 +01:00
Daniel Marjamäki
8925299947
Attempt to fix MSVC compile issue
2019-02-01 00:09:07 +01:00
IOBYTE
98fc6d1d32
Fixed #8959 ("(debug) Unknown type 'x'" with using/alias) ( #1635 )
...
* Fixed #8959 ("(debug) Unknown type 'x'" with using/alias)
* fix cppcheck warning
2019-01-31 23:57:37 +01:00
Daniel Marjamäki
53967c83e9
Fixed compile error
2019-01-31 23:52:48 +01:00
Daniel Marjamäki
961f66baff
Fixed #8820 (import GUI project)
...
This has basic handling of GUI projects. But further work will be needed to handle addons etc, the plan is that we will be able to run addons from the command line soon.
2019-01-31 20:40:21 +01:00
IOBYTE
05a3e6807b
Fixed #8950 and #8952 (improve type alias support) ( #1633 )
...
* Fixed #8950 and #8952 (improve type alias support)
* fix travis build
2019-01-31 16:53:51 +01:00
Paul Fultz II
c176775afb
Avoid infinite recursion in getLifetimeVariable ( #1634 )
...
* Fix direct recursion
* Limit depth of getLifetimeVariable
2019-01-31 10:34:41 +01:00
rikardfalkeborn
7779a9186e
Use valueflow in unsigned less than zero checker ( #1630 )
...
The unsigned less than zero checker looked for patterns like "<= 0".
Switching to use valueflow improves the checker in a few aspects.
First, it removes false positives where instead of 0, the code is using
0L, 0U, etc. Instead of having to hard code the different variants of 0,
valueflow handles this automatically. This fixes FPs on the form
uint32_t value = 0xFUL;
void f() {
if (value < 0u)
{
value = 0u;
}
}
where 0u was previously not recognized by the checker. This fixes #8836 .
Morover, it makes it possible to handle templates properly. In commit
fa076598ad
, all warnings inside templates
were made inconclusive, since the checker had no idea if "0" came from
a template parameter or not.
This makes it possible to not warn for the following case which was
reported as a FP in #3233
template<int n> void foo(unsigned int x) {
if (x <= n);
}
foo<0>();
but give a warning for the following case
template<int n> void foo(unsigned int x) {
if (x <= 0);
}
Previously, both these cases gave inconclusive warnings.
Finally, it makes it possible to give warnings for the following code:
void f(unsigned x) {
int y = 0;
if (x <= y) {}
}
Also, previously, the checker for unsigned variables larger than 0, the
checker used the string of the astoperand. This meant that for code like
the following:
void f(unsigned x, unsigned y) {
if (x -y >= 0) {}
}
cppcheck would output
[unsigned-expression-positive.c] (style) Unsigned variable '-' can't be negative so it is unnecessary to test it.
using expressionString() instead gives a better error message
[unsigned-expression-positive.c] (style) Unsigned expression 'x-z' can't be negative so it is unnecessary to test it.
2019-01-31 09:30:29 +01:00
Daniel Marjamäki
18e6a09739
astyle formatting
...
[ci skip]
2019-01-29 09:48:18 +01:00
Paul Fultz II
165a22ed0f
Lifetime: Support analysis with functions that do not return a reference ( #1632 )
...
* Initial support for function return
* Add test case
* Add support for reference parameters
* Format
2019-01-29 09:47:52 +01:00
Daniel Marjamäki
54cebfaf94
Fixed #8392 (false positive: "Memory leak" with malloc in if)
2019-01-27 10:27:44 +01:00
IOBYTE
606ba4fc1a
template simplifier: add forward declaration map to debug output ( #1629 )
...
* template simplifier: add forward declaration map to debug output
* template simplifier: add partial specialization flag
* template simplifier: add specialization map and partial specialization map to debug output
2019-01-27 07:46:27 +01:00
Daniel Marjamäki
2bba9ac78a
Fixed #8948 (False Positive: Variable 'n' is assigned a value that is never used.)
2019-01-26 21:44:07 +01:00
Paul Fultz II
d6aaf401df
Lifetime: Follow functions that return references
...
This will now warn for cases like this:
```cpp
int& f(int& a) {
return a;
}
int& hello() {
int x = 0;
return f(x);
}
```
2019-01-26 11:03:57 +01:00
IOBYTE
68bbe15116
template simplifier: fix missing instantiation ( #1627 )
2019-01-26 07:08:54 +01:00
IOBYTE
cb1a1df0fa
template simplifier: fix out of line member function scope and use more full name matching ( #1617 )
2019-01-24 07:21:22 +01:00
IOBYTE
ec8bc785a2
template simplifier: add support for using namespace when instantiating templates ( #1615 )
2019-01-23 08:53:01 +01:00
Paul Fultz II
3975913637
Extend lifetime checking for references
...
This will use the lifetime checker for dangling references. It will find these cases for indirectly assigned reference:
```cpp
int &foo()
{
int s = 0;
int& x = s;
return x;
}
```
This will also fix issue 510 as well:
```cpp
int &f( int k )
{
static int &r = k;
return r;
}
```
2019-01-23 07:29:16 +01:00
Daniel Marjamäki
8c07be136a
Fixed #8949 (False Positive: Variable 'f' is assigned a value that is never used.)
2019-01-22 21:16:27 +01:00
Daniel Marjamäki
149d688e9a
Fix return value from ErrorLogger::reportUnmatchedSuppressions
2019-01-22 06:45:22 +01:00
Daniel Marjamäki
4119cfd3d1
Correct exit code when there are no unmatched suppressions
2019-01-21 20:33:22 +01:00
Paul Fultz II
4b37f276c2
ValueFlow: Set arrays to true when converting to a boolean
...
This sets it by checking the parent. It doesn't handle function parameters yet.
2019-01-21 20:05:35 +01:00
Daniel Marjamäki
91435310cb
Fixed #8925 (compile_commands.json: False positives in .mm (Objective-C++) files, that file type should maybe just be ignored)
2019-01-21 06:36:31 +01:00
Daniel Marjamäki
a26287f491
Fix Token::findExpressionStartEndTokens() regression
2019-01-20 13:23:19 +01:00
Daniel Marjamäki
8da4e31c42
Fixed #8941 (False Positive: Variable 'f' is assigned a value that is never used.)
2019-01-20 13:20:23 +01:00
IOBYTE
1acbdde302
Fixed #7417 ("syntax error" in valid code containing explicitly specialised variable template) ( #1604 )
2019-01-18 21:12:39 +01:00
Sebastian
4b1544d33b
library.cpp: Let tinyxml2 print a helpful error message when XML is bad ( #1609 )
...
In case the XML code of a library configuration is invalid Cppcheck now additionally prints out some helpful error description like this:
"Error=XML_ERROR_MISMATCHED_ELEMENT ErrorID=16 (0x10) Line number=304: XMLElement name=noreturn"
2019-01-18 17:10:41 +01:00
Lauri Nurmi
3bbd9fc9a4
Replace "virtual method" with "virtual function" in messages.
...
The term "method" is not really a part of C++ terminology.
2019-01-15 06:22:14 +01:00
Lauri Nurmi
f267900257
Fix spelling of "overridden" in function names.
...
One 'd' was missing.
2019-01-15 06:22:14 +01:00
Robert Reif
6ef8dad459
template simplifier: improve namespace matching
...
* out of line member functions are a namespace
* template<...> and *_cast<> can't be instantiations
* refactor code to use less function parameters
* fix instantiation scopes
* use full name with namespace when available
* fallback to just matching names when full name doesn't match
2019-01-14 21:32:58 +01:00
IOBYTE
f0cfe03f7b
template simplifier: add cli --debug-template option to print the parsed template information ( #1598 )
2019-01-14 08:29:32 +01:00
Daniel Marjamäki
51afcb2f64
Fix Cppcheck missingOverride warnings
2019-01-13 13:22:36 +01:00
Daniel Marjamäki
0c08503b00
Travis: Enable missingOverride checker
2019-01-13 12:21:01 +01:00
Daniel Marjamäki
5f198662ff
rephraze internal warning
2019-01-13 12:12:07 +01:00
Daniel Marjamäki
c75a2265c0
Fix inline suppression.
2019-01-13 12:10:26 +01:00
Daniel Marjamäki
43035ff186
Remove inline suppression. The Cppcheck warning was a true positive.
2019-01-13 08:42:48 +01:00
Daniel Marjamäki
d50c3de740
Remove inline suppression and fix false positive.
2019-01-13 07:59:41 +01:00
Daniel Marjamäki
e6edd74099
Temporarily suppress Cppcheck false positives
2019-01-12 19:11:44 +01:00
Daniel Marjamäki
d40314b825
Replace Token::Match with Token::simpleMatch for simple patterns
...
[ci skip]
2019-01-12 18:44:48 +01:00
Daniel Marjamäki
2b1b8f8fe9
Fix Cppcheck warnings
...
[ci skip]
2019-01-12 18:29:08 +01:00
Daniel Marjamäki
1cd16cf94f
Suppressions: Handle comment in file that starts with #
2019-01-12 15:21:47 +01:00
Daniel Marjamäki
8b5f36670a
Introduce macro OVERRIDE for gcc-4.6 compatibility.
2019-01-12 07:37:42 +01:00
Daniel Marjamäki
c6b48b67f9
astyle formatting
...
[ci skip]
2019-01-11 16:37:12 +01:00
juremenart
45def06d59
fix trailing / from CMAKE JSON file and update unittests to cover both (w and w/o cases) ( #1592 )
...
* fix for CMake compile_commands.json input - director does not include trailing / which makes include directories wrong - so add it if it doesnt exist
* fix the bugfix for trailing / in the directory name of CMAKE JSON file, add also new test case to see if it works in both cases (with and without trailing /)
* revert adding accidental new line
2019-01-11 16:36:55 +01:00
versat
991191450a
astyle formatting
...
[ci skip]
2019-01-11 12:56:31 +01:00
Paul Fultz II
921f6e4313
Fix issue 8883: False positive: returnDanglingLifetime with local struct or class ( #1585 )
2019-01-11 09:51:02 +01:00
Paul Fultz II
5fa956a597
Fix issue 8932: False positive knownConditionTrueFalse - valueflow ignores operator < ( #1584 )
2019-01-11 08:39:23 +01:00
Daniel Marjamäki
8509159d1a
Uninitialized Member variable: Fixed FP when delegate constructor is used
2019-01-10 20:13:37 +01:00
rikardfalkeborn
a48c8abcda
Fix 8124: False positive va_end missing with lambda ( #1577 )
...
Skip lambdas, to avoid false positives due to possible
return statements in lambdas.
Also, run dmake.
2019-01-10 18:32:17 +01:00
Paul Fultz II
4e147a4c59
Add a check for duplicate if statements
...
This will warn for this:
```cpp
int f(int val)
{
int i = 0;
if( val & 0xff)
i = 1;
if( val & 0xff)
i = 1;
return i;
}
```
2019-01-09 20:41:01 +01:00
Daniel Marjamäki
35e56942d1
Fixed #8116 ([False positive] Invalid memory leak detection when using reference.)
2019-01-09 20:38:32 +01:00
Daniel Marjamäki
75e367c48b
Fixed #8340 (incorrect memleak errors)
2019-01-09 19:50:41 +01:00
ivangalkin
5ddc6c64d7
CheckStl: add missing error ID iterators2 ( #1576 )
...
due to equal arguments...
* iterators1 (`CheckStl::iteratorsError(const Token*, const std::string&, const std::string&)`) and
* iterators2 (`CheckStl::iteratorsError(const Token*, const Token*, const std::string&, const std::string&)`)
... produced equal messages. Equal messages were filtered-out `CppCheck::reportErr(const ErrorLogger::ErrorMessage&)`.
So the error iterators2 disapeared from the error list.
2019-01-09 06:45:38 +01:00
Daniel Marjamäki
0f9ce5edd5
Fixed #8365 (False positive on memory leak when assigned inside if statement)
2019-01-08 20:54:39 +01:00
Daniel Marjamäki
e4525d56a0
Fixed #8111 (performance warning - member variable at constructor)
2019-01-07 21:26:58 +01:00
IOBYTE
07da4b4d37
template simplifier: Add flag variable to cache information about dec… ( #1569 )
...
* template simplifier: Add flag variable to cache information about declarations.
Also fix some cppcheck warnings.
* Make variable const.
2019-01-07 06:55:22 +01:00
practicalswift
0a1b3a9d6f
Fix typos ( #1568 )
2019-01-06 17:15:57 +01:00
Daniel Marjamäki
5636497c0b
Fixed #8863 (false positive: (warning) Accessing an item in container 's'. Either the condition 's.empty()' is redundant or 's' can be empty.)
2019-01-06 12:21:55 +01:00
Daniel Marjamäki
ea0232653f
Fixed #8563 (CPPCheck not able to locate file through compilation database)
2019-01-05 23:11:43 +01:00
IOBYTE
817c748e4d
Fixed #5953 (debug: varid0: Function::addArguments) ( #1567 )
2019-01-05 19:42:04 +01:00
Daniel Marjamäki
36ffa91825
Replace std::set::emplace with std::set::insert to make Cppcheck compilable in Slackware 14.0
2019-01-05 18:18:15 +01:00
Daniel Marjamäki
5f5c33baf2
Json: Use simple json library picojson to read compile databases
2019-01-05 17:45:07 +01:00
Daniel Marjamäki
615903c6be
Improve syntax errors for unmatched (){}[]
2019-01-05 11:56:21 +01:00
IOBYTE
32a5d66e5b
Fixed #8927 (SIGSEGV below TemplateSimplifier::expandTemplate) ( #1564 )
2019-01-05 11:14:09 +01:00
Paul Fultz II
bba6dfb8b2
Fix issue 4744: ValueFlow: known integer result
...
This fixes valueflow to have a value for `||` operator here:
```cpp
bool f()
{
bool a = (4 == 3); // <-- 0
bool b = (3 == 3); // <-- 1
return a || b; // <-- 1
}
```
2019-01-03 07:05:31 +01:00
Daniel Marjamäki
2b63997c2c
Fixed #8928 (false positive: (style) Variable 'x' is assigned a value that is never used.)
2019-01-02 20:23:02 +01:00
Daniel Marjamäki
39ceb53578
Comment out code in valueFlowArray. There was too many false positives.
2019-01-02 19:57:11 +01:00
Daniel Marjamäki
39a96a5a16
ValueFlow: Temporarily comment out valueFlowTerminatingCondition
2019-01-02 19:42:08 +01:00
Daniel Marjamäki
7a40b85531
Fixed #8906 (Encoding error in XML message: info attribute)
2019-01-02 18:22:12 +01:00
amai2012
af639e9848
#7772 Add uninitMemberVarPrivate to errorlist ( #1557 )
2019-01-02 18:08:39 +01:00
Daniel Marjamäki
236c88151f
Fixed #8926 (false positive: (style) Condition 's.x<=y' is always true)
2019-01-02 18:05:55 +01:00
IOBYTE
3b9828a132
template simplifier: fix crash on daca c++-annotations project ( #1556 )
...
Fix scope info bug on derived template class which caused a use after
free crash when deleting a template forward declaration in a different
scope.
2019-01-02 07:15:45 +01:00
Daniel Marjamäki
19514331fb
Fixed #8907 (unknown macro not detected)
2019-01-01 19:30:13 +01:00
Daniel Marjamäki
115be7dfc8
ValueFlow: better FwdAnalysis for complex expressions
2019-01-01 18:23:47 +01:00
Daniel Marjamäki
be7afac875
ValueFlow: remove handling of == for complex expressions it did not work properly
2019-01-01 17:23:46 +01:00
Daniel Marjamäki
20436ea986
Fix compiler warning
2019-01-01 17:04:47 +01:00
rikardfalkeborn
13ffefc8b8
Valueflow: Fix right shift with more than 31 bits ( #1553 )
...
When comparing if the shift is large enough to make the result zero, use
an unsigned long long to make sure the result fits. Also, a check that
avoids setting the value if the shift is equal to or larger than the
number of bits in the operand (this is undefined behaviour). Finally,
add a check to make sure the calculated value is not too large to store.
Add test cases to cover this.
This was detected by an MSVC warning.
valueflow.cpp(1350): warning C4334: '<<' : result of 32-bit shift implicitly
converted to 64 bits (was 64-bit shift intended?)
2019-01-01 14:15:50 +01:00
Daniel Marjamäki
a73e989d1a
isConstVarExpression: Fix FPs when there is C++ cast
2019-01-01 11:34:44 +01:00
Daniel Marjamäki
04d3672bde
Fixed #7203 (Better syntax error, handle array declaration with @)
2019-01-01 09:45:41 +01:00
IOBYTE
c37b807613
template simplifier: also check if instantiated template is not specialized ( #1551 )
2018-12-31 21:29:53 +01:00
Daniel Marjamäki
ac357a96f7
Fixed #7384 (confuses syntax with variable name / "variable '(' is less than zero")
2018-12-31 18:36:06 +01:00
Daniel Marjamäki
ed514644b8
Renamed FwdAnalysisAllPaths to FwdAnalysis
2018-12-31 18:00:47 +01:00
Daniel Marjamäki
4918a18bfb
ValueFlow: Value of expression after condition
2018-12-31 17:37:38 +01:00
IOBYTE
9dc8faa3b6
template simplifier: fix location of forward declaration for explicit specializations ( #1550 )
2018-12-31 17:19:34 +01:00
Daniel Marjamäki
141ce7cd63
ValueFlow: Use FwdAnalysisAllPaths in ValueFlow to track complex expressions
2018-12-31 17:05:46 +01:00
Daniel Marjamäki
fd8f599802
CTU: Use column in function id
2018-12-31 10:18:28 +01:00
Daniel Marjamäki
aa4f61acdf
CTU: Avoid FP in else block
2018-12-31 08:24:39 +01:00
Daniel Marjamäki
fb6a291370
CTU: Avoid FP in code protected by &&,||,?
2018-12-31 08:16:21 +01:00
Daniel Marjamäki
a520a41e64
CheckUninitVar: Try to report all CTU issues not just the first found issue
2018-12-31 07:54:00 +01:00
Daniel Marjamäki
37a3544ff5
CheckNullPointer: Try to report all CTU issues not just the first found issue
2018-12-31 07:52:14 +01:00
Daniel Marjamäki
5cc61e55f9
CTU: Refactoring; Use ValueFlow::Value::errorSeverity
2018-12-31 07:50:02 +01:00
amai2012
f2d7cb3ab6
Fix VS compiler warning and add a const
2018-12-30 22:17:21 +01:00
IOBYTE
36dfa0f27a
template simplifier: refactor to use cached information ( #1548 )
...
* use already cached name token rather than recalculating it
multiple times
* cache end of template parameters token and use it rather than
recalculating it multiple times
* remove unnecessary end of template token and name token checks
* remove function parameter that is already contained in another
parameter
2018-12-30 21:16:11 +01:00
Daniel Marjamäki
6b49a784c5
Fixed #8911 (Regression: False positive: Unassigned variable (alias))
2018-12-30 20:20:20 +01:00
amai2012
73fa941352
Doxygen fixes
2018-12-30 19:31:50 +01:00
Daniel Marjamäki
91a580cbd7
CTU: more warnings
2018-12-30 18:31:37 +01:00
Daniel Marjamäki
c8901e9bab
CTU: Find paths better
2018-12-30 16:23:25 +01:00
Daniel Marjamäki
b3fcd8a685
astyle formatting
...
[ci skip]
2018-12-30 11:59:06 +01:00
Daniel Marjamäki
378e083585
CTU: Refactoring the xml load/write. Renamed members.
2018-12-30 11:55:39 +01:00
Carlo Marcelo Arenas Belón
5ae6861a0f
clang warnings ( #1547 )
...
* valueflow: remove unused variable known
since e4677ae640
will trigger :
lib/valueflow.cpp:506:20: warning: unused variable 'known' [-Wunused-variable]
const bool known = (parent->astOperand1()->hasKnownValue() ||
* templatesimplifier: cleanup
since 48c960f56c
showing:
lib/templatesimplifier.h:279:16: warning: private field 'mTokenizer' is not used
[-Wunused-private-field]
Tokenizer *mTokenizer;
2018-12-30 11:32:48 +01:00
ivangalkin
3f318548e2
CheckNullPointer: Add missing id 'nullPointerArithmeticRedundantCheck' to errorlist ( #1535 )
...
* split CheckNullPointer::arithmeticError() into
* CheckNullPointer::pointerArithmeticError() and
* CheckNullPointer::redundantConditionWarning()
* Additional errorlist entry:
```XML
<error id="nullPointerArithmeticRedundantCheck"
severity="warning"
msg="Either the condition is redundant or there is pointer arithmetic with NULL pointer."
verbose="Either the condition is redundant or there is pointer arithmetic with NULL pointer." cwe="682"/>
```
2018-12-29 21:34:22 +01:00
IOBYTE
da91ce2016
Fixed #6183 (TemplateSimplifier: Does not handle methods) ( #1546 )
...
* Fixed #6183 (TemplateSimplifier: Does not handle methods)
* Fix function lookup.
2018-12-29 11:19:53 +01:00
Paul Fultz II
e4677ae640
Fix issue 8910: Regression: ValueFlow: wrong conditional tokvalue
...
This fixes issue in:
```cpp
void f()
{
char stack[512];
RGNDATA *data;
if (data_size > sizeof (stack))
data = malloc (data_size);
else
data = (RGNDATA *)stack;
if ((char *)data != stack)
free (data); // <- data is not stack
}
```
It seems the `ProgramMemory` can't handle two known values(such as int and tok) together. So instead `ValueFlowAfterAssign` runs `ValueFlowForward` with tok values and then runs it with the other values.
2018-12-29 09:31:21 +01:00
Daniel Marjamäki
d18f5d8709
CTU: Reuse CheckNullPointer::isPointerDeRef in the nullpointer isUnsafeUsage
2018-12-29 09:26:57 +01:00
amai2012
03ed4afc70
Export interfaces from cppcheck-core.dll used from testrunner. In turn remove ctu sources from testrunner which are obsolete now.
2018-12-28 23:09:44 +01:00
Oliver Schode
22504975b9
Patch assert warning lib/checkassert.cpp ( #1543 )
...
* Fixed typo in warning about modified variable inside assertion
* Fixed assert warning again in checkassert.cpp
2018-12-28 15:25:22 +01:00
Daniel Marjamäki
ee3fd0af03
Refactoring: Combine replaceStr functions
2018-12-28 13:11:54 +01:00
rikardfalkeborn
036fcf7827
Fix warnings ( #1541 )
...
* Fix reorder warning
* Fix override warnings
Clang warns about missing overrides.
* Remove unused function
* Add missing argument to function calls
2018-12-28 12:59:05 +01:00
amai2012
128ad96b59
Add ctu sources to VS projects
2018-12-27 22:11:40 +01:00
Daniel Marjamäki
a40fe3c67f
Fixed #7872 (ValueFlow: static_cast)
2018-12-27 21:33:01 +01:00
Daniel Marjamäki
6fef02498c
Fixed #7263 (False negative: redundant assignment using +=)
2018-12-27 17:27:53 +01:00
Daniel Marjamäki
a788512d66
CTU: Refactor isUnsafeFunction
2018-12-26 19:17:49 +01:00
Daniel Marjamäki
a6e227a73c
CTU: Refactoring; getErrorPath
2018-12-26 15:56:10 +01:00
Daniel Marjamäki
e39be48c92
CTU: Refactoring, create ErrorPath in ctu
2018-12-26 11:36:26 +01:00
Daniel Marjamäki
271763e680
CTU: Refactoring
2018-12-25 21:11:23 +01:00
Daniel Marjamäki
a1dca6acd5
Fix CTU nullpointer check
2018-12-25 12:04:01 +01:00
Daniel Marjamäki
ddbe5c129c
Clarify FwdAnalysis. It is useful for checks that need data flow analysis of ALL paths.
2018-12-25 11:56:06 +01:00
Daniel Marjamäki
c7993df4ff
Refactoring; Use range for loops
2018-12-25 11:47:45 +01:00
Daniel Marjamäki
162576146e
Revert "Fixed #6183 (TemplateSimplifier: Does not handle methods) ( #1540 )"
...
This reverts commit 7875555b03
.
2018-12-24 20:10:00 +01:00
Daniel Marjamäki
b3e6ecd827
Library: Make loading of cfg files more robust. Saw a problem to use --library=gtk when the current folder has a folder 'gtk'
2018-12-24 08:37:33 +01:00
IOBYTE
7875555b03
Fixed #6183 (TemplateSimplifier: Does not handle methods) ( #1540 )
2018-12-24 07:25:11 +01:00
Daniel Marjamäki
b79619832e
Clarify warning
2018-12-23 12:42:18 +01:00
IOBYTE
48c960f56c
template simplifier: better detection of template functions ( #1539 )
...
* template simplifier: better detection of template functions
* fix comment
2018-12-22 10:05:10 +01:00
Sebastian
b51f19d530
Fix some doxygen warnings/issues in the comments ( #1537 )
2018-12-21 21:23:03 +01:00
Daniel Marjamäki
b97b3b7ef8
astyle formatting
...
[ci skip]
2018-12-21 13:54:59 +01:00
rebnridgway
431d068339
Several fairly significant optimisations ( #1518 )
...
* Code changes for Token::mImpl optimisation
* Added new TokenImpl optimisation
Moving members to the TokenImpl struct reduces the size of the Token class, which is a fairly significant optimisation. In my testing on Windows with 32-bit Release-PCRE, this change reduced the size of the Token class from 108 bits to 52 bits and reduced run-time of my test case by around 20%.
* Several optimisations
Deleted some code that ran very slowly and did nothing, as there is no need to change a Token's string to null if you are about to delete it.
Added a frontToken to simplifyCalculations to reduce the amount of work it has to do on already-simplified calculations.
Moved template removal to the end of the list as this reduces redundant iteration and saves time.
* Added tok argument to simplifyCalculations
This means callers can avoid unnecessary work if they know which tokens have already been simplified. Passing nullptr indicates the original behaviour (starting from the front of the list).
* Removed mention of member from another change
* Re-added and optimised some code deleted in error
Changing mTemplateInstantiations to a vector avoids the high cost of doing repeated linear searches. Changing how the code iterates through the array was necessary because the vector can be resized at several points during the loop, which breaks existing references and iterators.
* Changed mTemplateInstantiations to a vector
This is an optimisation that makes repeated linear searches of this collection significantly faster.
Also added a copy constructor to TokenAndName so code can make copies of these objects to keep a reference if a vector gets resized.
* A cleaner optimisation to removing template tokens
This reverts the previous change to made mInstantiatedTemplates a vector and the iterator changes to support this, and makes mTypesUsedInTemplateInstantiation so the eraseTokens logic can be unified.
* Reverted vector to list
Also made mTypesUsedInTemplateInstantiation a vector of TokenAndName objects so it can share the same logic as the other members.
* Added member for template simplifier pointer
This can be used more efficiently than marking Tokens with a flag and then searching through all templates to find the one that matches.
* Turned loop inside out
This means we only have to iterate through the std::list once. std::list is very expensive to iterate through.
* Latest code from danmar and fixed optimisations
In particular I have optimised simplifying template instantiation names as this was incredibly slow because of the number of times it had to iterate through the template instantiation list. Previous optimisations to this weren't very effective and broke some edge cases.
* Added changes from danmar
Made mExplicitInstantiationsToDelete a vector of TokenAndName to be consistent with the rest of the members, which are cleaned up very efficiently.
* Tokens can have many templateSimplifierPointers
* templateSimplifierPointers must be kept in sync
2018-12-21 13:51:45 +01:00
Sebastian
a1a695dcda
checkio: Add missing id "invalidScanfFormatWidth_smaller" to errorlist output ( #1533 )
2018-12-20 21:14:02 +01:00
IOBYTE
d528934139
template simplifier: also remove forward declarations when removing expanded templates ( #1536 )
2018-12-20 20:55:27 +01:00
amai2012
19e979315f
Correct detection of Microsoft extensions in MathLib::isValidIntegerSuffix. Remove public overloaded implementation which was not used outside mathlib.cpp. ( #1531 )
2018-12-20 12:20:31 +01:00
IOBYTE
c31331d085
template simplifier: fix explicit instantiation with types starting with const and ending in * and &. ( #1530 )
2018-12-19 21:59:59 +01:00
Daniel Marjamäki
e2c433a0f8
Fixed #8914 (False positive with unary_function argument)
2018-12-19 19:43:05 +01:00
amai2012
378ffed37e
Address compiler warning
2018-12-19 14:39:04 +01:00
PKEuS
34874dd94f
Optimization: Removed unnecessary calls to simplifyPath(). The Caller should do this, and our callers (mainly the test suite) more or less do so, as they all supply just dummy paths ("test.cpp")
2018-12-18 20:33:45 +01:00
Daniel Marjamäki
bc34f0239d
Disable the subfunction value flow analysis. It does not work well and needs to be rewritten. There are false positives.
2018-12-18 14:36:49 +01:00
Paul Fultz II
34330b51d1
Fix issue 8905: Condition 'a==0' is always false
...
This fixes the FP in:
```cpp
void f(const int a[]){ if (a == 0){} }
```
2018-12-18 08:16:43 +01:00
IOBYTE
1cba78090c
Fix const anonymous struct. ( #1527 )
2018-12-18 08:15:12 +01:00
Daniel Marjamäki
0f63874c62
Take back the whole program analysis for null pointers and uninitialized variables
2018-12-18 07:56:33 +01:00
Daniel Marjamäki
643ddd4caa
Code cleanup
2018-12-17 18:54:32 +01:00
Daniel Marjamäki
3b328f9187
CheckMemoryLeak: Cleanup the old memory leaks check
2018-12-17 18:12:50 +01:00
Daniel Marjamäki
f118c22bb6
CheckUnusedVar: Cleanup checker
2018-12-17 17:48:45 +01:00
Daniel Marjamäki
cf09fd6274
CheckUnusedVar: Code cleanup
2018-12-17 17:28:15 +01:00
Daniel Marjamäki
fe38e256cc
Fixed #7907 (FN: redundant assignment inside switchcase, overwritten by assignment outside of switch)
2018-12-17 16:10:47 +01:00
Daniel Marjamäki
bf4e850e11
Fixed #4475 (New check: struct member is assigned a value that is not read)
2018-12-17 15:40:15 +01:00
Daniel Marjamäki
858d9a18a7
Fixed #3857 (false negative: (style) Variable 'var' is assigned a value that is never used)
2018-12-17 15:16:47 +01:00
Paul Fultz II
025881cf35
Fix issue 8829: Condition '...' is always true (int buf[42]; if(buf != NULL){})
...
This makes arrays non-null in valueflow, so it can catch comparisons against null that is always true:
```cpp
void f(void) {
int buf[42];
if( buf != 0) {;} // << always true
}
```
2018-12-17 06:07:34 +01:00
Paul Fultz II
9b973e652c
Issue 8830: New check: Function argument evaluates to constant value
...
Add a check for function arguments that can be constant:
```cpp
extern void bar(int);
void f(int x) {
bar((x & 0x01) >> 7); // function 'bar' is always called with a '0'-argument
}
```
2018-12-17 06:04:24 +01:00
IOBYTE
2090866cd0
template simplifier: remove explicit instantiations after instantiation ( #1523 )
...
* template simplifier: remove explicit instantiations after instantiation
* Fix use after free crash in clang test suite.
2018-12-17 05:58:48 +01:00
Daniel Marjamäki
c8d688607a
Fixed #8901 (Unused value: const variable initialization)
2018-12-16 19:01:05 +01:00
Daniel Marjamäki
21eb1c5e22
FwdAnalysis: Fix false negatives for struct members
2018-12-16 18:32:34 +01:00
Daniel Marjamäki
46a0172480
FwdAnalysis: fix FP in loop
2018-12-16 16:43:04 +01:00
Daniel Marjamäki
97d2075007
FwdAnalysis: better handling of loops
2018-12-16 11:42:11 +01:00
Daniel Marjamäki
3af0d73f82
Unused value: Fixed false negatives for loops
2018-12-16 11:18:37 +01:00
Paul Fultz II
3262a3bebe
Add isSameExpression to valueflow analysis
...
Check for same expressions in valueflow analysis.
2018-12-16 07:35:27 +01:00
Paul Fultz II
45dcfad9f9
Fix issue 8899: False positive returnDanglingLifetime when returning by value
...
This fixes the FP from:
```cpp
#include <string>
class MyString
{
public:
MyString(char* source)
{
length = strlen( source );
buffer = new char[length+1];
if( buffer )
{
strcpy( buffer, source );
}
}
char* buffer;
int length;
};
MyString Foo()
{
char arr[20];
sprintf(arr, "hello world");
return arr;
}
void main()
{
MyString str = Foo();
printf(str.buffer);
}
```
2018-12-15 17:58:45 +01:00
Daniel Marjamäki
1bfe98447a
FwdAnalysis: Tweak possiblyAliased
2018-12-15 11:54:00 +01:00
Daniel Marjamäki
f26549e5ab
Fixed #8896 (Tokenizer: Anonymous struct)
2018-12-15 08:42:35 +01:00
IOBYTE
a1c275436f
Fix #8902 (Crash in TemplateSimplifier) ( #1521 )
2018-12-15 07:52:47 +01:00
Daniel Marjamäki
37416010ef
Unused value: Fix false positive (ast, {})
2018-12-14 18:56:09 +01:00
Paul Fultz II
be6782d386
Fix FP 8891: Incorrect return scope when using uniform initialization
...
This fixes the FP in:
```cpp
std::string f(const std::string& data)
{
if (data.empty())
return {};
data[0];
}
```
2018-12-14 18:31:10 +01:00
Daniel Marjamäki
8464085535
UnusedVariables: Fix FP for unknown variable
2018-12-13 21:37:21 +01:00
Daniel Marjamäki
092d434f91
UnusedVar: Fix FP for array arguments
2018-12-13 21:08:18 +01:00
Daniel Marjamäki
1f27cd56c0
FwdAnalysis; Code cleanup, isNullOperand
2018-12-13 21:01:33 +01:00
Daniel Marjamäki
0b4e08cac9
Use FwdAnalysis in UnusedVar. This is still work-in-progress. Merging to master branch so it can be tested.
2018-12-13 18:52:56 +01:00
IOBYTE
0f83aff3b8
Improve trailing return type support. ( #1520 )
...
* Improve trailing return type support.
* Partial fix for #8889 (varid on function when using trailing return type)
* Handle operators in templates.
2018-12-13 06:34:10 +01:00
Daniel Marjamäki
e0b64ec7a9
Fixed #8884 (AST: handle xs... template argument)
2018-12-12 19:00:14 +01:00
amai2012
6924522475
Refactor methods for identification of numeric literals. ( #1514 )
2018-12-10 12:10:26 +01:00
PKEuS
886aa07ffb
Set version to 1.86.99/1.87 dev
2018-12-08 11:53:37 +01:00
Daniel Marjamäki
a16f694254
Revert "Fix issue 8884: Regression: False positive: Variable 'f' is reassigned a value before the old one has been used ( #1513 )"
...
This reverts commit 6953dddfa6
.
2018-12-08 08:25:20 +01:00
Daniel Marjamäki
5e527bdd08
Update version
2018-12-08 08:17:05 +01:00
Paul Fultz II
6953dddfa6
Fix issue 8884: Regression: False positive: Variable 'f' is reassigned a value before the old one has been used ( #1513 )
2018-12-08 07:33:51 +01:00
amai2012
a68086c959
Implement hexadecimal float conversion in MathLib::toDoubleNumber ind… ( #1506 )
...
* Implement hexadecimal float conversion in MathLib::toDoubleNumber independent of C99/C++17
* Refactor MathLib::isFloatHex and cure some false results
2018-12-06 22:16:16 +01:00
IOBYTE
a90c56ad76
Fixed #8880 (Regression: syntax error for valid C++ template code) ( #1509 )
2018-12-06 21:47:48 +01:00
Daniel Marjamäki
bd0a935d8a
Tokenizer: Improved handling of compiler extensions that use @ (see https://sourceforge.net/p/cppcheck/discussion/general/thread/8f618cb0a3 )
2018-12-04 19:33:39 +01:00
Daniel Marjamäki
88c61e8d1e
ValueFlow: Avoid FP when lambda is used
2018-12-04 18:54:26 +01:00
Daniel Marjamäki
452318dfa4
Remove FwdAnalysis::reads: It is not finished
2018-12-04 18:46:23 +01:00
Daniel Marjamäki
f5a94ed300
ValueFlow: Fix FP when lambda is called
2018-12-04 18:46:00 +01:00
Daniel Marjamäki
49413b7d4c
Tokenizer: Add simplifyAt to handle some nonstandard code with @
2018-12-04 16:52:41 +01:00
Daniel Marjamäki
7ef8f60b07
Fixed #8817 (Change wording in performance/functionStatic)
2018-12-03 18:30:54 +01:00
Daniel Marjamäki
c03c262058
Preparing FwdAnalysis for ValueFlow usage where we want to fetch read locations
2018-12-02 18:29:16 +01:00
Daniel Marjamäki
d8fada6702
Refactoring FwdAnalysis
2018-12-02 17:42:18 +01:00
Daniel Marjamäki
6734571f06
Refactoring: Create FwdAnalysis class in astutils
2018-12-02 17:01:52 +01:00
Igor
61878c5e11
Add null pointer check to fix SEGFAULT ( #1499 )
...
* Add null pointer check to fix segfault
* Add first test case to reproduce problem
2018-12-02 14:36:01 +01:00
Paul Fultz II
3e1b34dd8f
Fix FPs and crashes with byDerefCopy ( #1503 )
...
* Fix FP when inserting a range into a container
* Formatting
* Fix crash
2018-12-02 14:31:31 +01:00
Daniel Marjamäki
ba564076db
Fixed #7907 (FN: redundant assignment inside switchcase, overwritten by assignment outside of switch)
2018-12-02 14:04:59 +01:00
Daniel Marjamäki
88785dda02
Refactoring the redundant assignments check
2018-12-02 11:41:27 +01:00
Daniel Marjamäki
8087cfed5d
Fixed #8627 (Tokenizer::setVarIdPass2: constructor parameter)
2018-12-02 09:28:05 +01:00
Paul Fultz II
b841b818d2
Fix 8872: Crash in LifetimeStore when there is no scope for variable
...
This fixes crash in:
```cpp
struct edit_line_paste_over {
void operator()(agi::Context *c) override {
paste_lines(c, true, [&](AssDialogue *new_line) -> AssDialogue * {
AssDialogue *ret = paste_over(c->parent, pasteOverOptions, new_line, static_cast<AssDialogue*>(&*pos));
return ret;
});
}
};
```
2018-12-01 19:11:26 +01:00
Paul Fultz II
67dd822910
Fix FP in lifetime anlaysis: Dont decay std array
...
This will fix FP with:
```cpp
std::array<char, 1> f() {
std::array<char, 1> x;
return x;
}
```
2018-12-01 19:09:19 +01:00
Paul Fultz II
229c45e7f8
Fix issue 8865: FP with dangling lifetime
...
This fixes:
```cpp
void f(uint32_t event, unsigned long op, const xen_ulong_t *args)
{
struct __packed {
uint32_t op;
uint32_t args[6];
} d;
uint32_t *a = d.args;
}
```
2018-12-01 19:07:46 +01:00
Daniel Marjamäki
2c803a1ead
Revert " #6514 Try to support hexadecimal floating numbers in MathLib::toDoubleNumber"
...
This reverts commit a73decf7e4
.
2018-12-01 19:01:51 +01:00
Daniel Marjamäki
3fadefe318
Revert "Add missing include"
...
This reverts commit a2b6eaf311
.
2018-12-01 19:00:42 +01:00
Daniel Marjamäki
96929c53c0
Fixed #8873 (Add syntaxError when there is no RHS for +-)
2018-12-01 17:29:41 +01:00
Daniel Marjamäki
f42648fe22
Fixed #8114 (false positive: Address of local auto-variable assigned to a function parameter.)
2018-12-01 10:11:02 +01:00
amai2012
a2b6eaf311
Add missing include
2018-12-01 01:36:04 +01:00
amai2012
a73decf7e4
#6514 Try to support hexadecimal floating numbers in MathLib::toDoubleNumber
2018-12-01 00:50:26 +01:00
Colomban Wendling
cad4e4ab20
Fix handling of `sizeof &var` ( #1498 )
...
Fixes https://trac.cppcheck.net/ticket/8870
2018-11-30 13:53:58 +01:00
IOBYTE
3d024f3f6d
template simplifier: fix function forward declaration bug for constructor with initializer list. ( #1497 )
2018-11-29 06:24:28 +01:00
Daniel Marjamäki
ff469867e7
Refactor CheckStl::stlOutOfBounds
2018-11-28 20:30:58 +01:00
Daniel Marjamäki
dd94bfede9
CheckStl: Improving checking of container access out of bounds
2018-11-28 19:27:28 +01:00
Daniel Marjamäki
6493db6ca2
Try to clarify message for container access out of bounds a little more.
2018-11-28 13:58:01 +01:00
Daniel Marjamäki
0f2f807798
Improve the container out of bounds messages. They are still not perfect.
2018-11-28 07:03:56 +01:00
Daniel Marjamäki
13c6489571
Redundant variable assignment: Fix FN for struct members
2018-11-27 18:22:22 +01:00
Daniel Marjamäki
32c05fef92
Redundant assignment: check that --enable=style has been used.
2018-11-27 13:04:50 +01:00
Daniel Marjamäki
0ad757fc78
valueFlowLifetime: Try to cleanup the loop a little. No functional change is intended.
2018-11-27 06:43:59 +01:00
Paul Fultz II
5a6f9ac82a
Fix FP with strcmp and terminating conditions
2018-11-27 06:39:29 +01:00
IOBYTE
f2660ed203
template simplifier: fix instantiated template names in forward declarations ( #1495 )
...
This now handles the revised example code in #8603 .
2018-11-27 06:17:04 +01:00
Daniel Marjamäki
2887ee10c0
Fixed #8800 (Possible variable assignment ignored in boolean expression)
2018-11-26 14:00:03 +01:00
Daniel Marjamäki
affd03f1d6
Minor tweak for redundantVariableAssignment
2018-11-26 11:16:50 +01:00
IOBYTE
e20079a5d9
template simplifier: fix 3 function forward declaration bugs ( #1493 )
...
* fix support for multi token types
* fix support for const member functions
* fix duplicate template parameters sometimes being inserted
2018-11-26 06:23:12 +01:00
Daniel Marjamäki
86f9fb778b
Fixed #8864 (compile commands: handle define with string value)
2018-11-25 15:09:23 +01:00
Daniel Marjamäki
0160f80ffe
redundantVarAssignment: avoid FPs when loops are used
2018-11-25 10:32:30 +01:00
Daniel Marjamäki
22f736eae2
redundant variable assignments: avoid FPs for initializations
2018-11-25 08:49:09 +01:00
Daniel Marjamäki
2f66b31d43
redundantAssignmentInSwitch: fix false positive when there is goto
2018-11-24 21:39:01 +01:00
Paul Fultz II
a3921ea861
Refactor valueFlowAfterCondition
...
So this unifies the `valueFlowAfterCondition` so it re-uses more code between checking for integers and container sizes. This should make valueFlowContainer more robust.
It also extends valueflow to support container comparisons such as `if (v.size() < 3)` or `if (v.size() > 3)` using the same mechanism that is used for integers.
2018-11-24 10:07:12 +01:00
Daniel Marjamäki
866688c70a
Rewriting redundantAssignment checker
2018-11-24 10:03:54 +01:00
Daniel Marjamäki
b049a31e7c
Refactoring; Use visitAstNodes
2018-11-23 20:41:39 +01:00
Daniel Marjamäki
2b09354b05
Refactoring; use visitAstNodes
2018-11-23 20:33:31 +01:00
Daniel Marjamäki
2214ef5359
Refactor isVLAIndex
2018-11-23 20:23:20 +01:00
Daniel Marjamäki
8f164d9602
Refactoring; use visitAstNodes
2018-11-23 19:22:53 +01:00
Daniel Marjamäki
52f9650533
Refactoring: Use visitAstNodes
2018-11-23 19:16:19 +01:00
Daniel Marjamäki
745b58de26
Refactoring: Use visitAstNodes
2018-11-23 17:18:07 +01:00
IOBYTE
358f0c473d
Modify template simplifier to add forward declarations of some templa… ( #1489 )
...
* Modify template simplifier to add forward declarations of some template functions so symbol database can make sense of the expanded templates.
* Fix travis.
2018-11-23 11:36:09 +01:00
Daniel Marjamäki
ecb3c04fba
astutils: Add function that visits nodes in AST tree
2018-11-23 06:53:43 +01:00
Paul Fultz II
f16d9d7d90
Issue 6175: Check lifetime of a variables stored in containers and member variables
...
Cppcheck will now warn for all cases here:
```cpp
#include <vector>
class CCluster {};
class MyClass
{ public:
std::vector<CCluster*> m_cluster;
void createCluster()
{
CCluster cl;
CCluster* pcl=&cl;
m_cluster.push_back(pcl);
}
void createCluster2()
{
CCluster cl;
m_cluster.push_back(&cl);
}
CCluster* Cluster()
{
CCluster cl;
CCluster* pcl=&cl;
return pcl;
}
CCluster* Cluster2()
{
CCluster cl;
return &cl;
}
};
```
2018-11-21 08:43:57 +01:00
Daniel Marjamäki
9d8e5e36eb
Added a few TODO comments
2018-11-20 22:57:01 +01:00
Daniel Marjamäki
8227188786
comment out old memleak checking. maybe it can be removed.
2018-11-20 18:40:18 +01:00
Daniel Marjamäki
a5af5b2d08
Revert "Fixed #7619 (False positive: Redundant assignment)"
...
There is a crash I need to look into.
2018-11-20 06:23:43 +01:00
Daniel Marjamäki
c899792232
Fixed #7619 (False positive: Redundant assignment)
2018-11-19 21:23:36 +01:00
Daniel Marjamäki
a8cbbe0e16
Fixed #8816 (FP shadowLocal - variable shadows a template function?)
2018-11-19 07:00:15 +01:00
Daniel Marjamäki
9ef3c79bc6
Fixed #8851 (Crash in valueFlowContainerForward (daca@home: pbbam))
2018-11-18 20:18:55 +01:00
Daniel Marjamäki
f2b26a488a
relative paths: another fix for {code}
2018-11-18 16:15:09 +01:00
Daniel Marjamäki
982f7dc2b3
relative paths: show {code} properly when there are relative paths
2018-11-18 16:08:08 +01:00
Paul Fultz II
7ef119cbfc
Fix FPs in lifetime checker
...
This fixes several FPs in the lifetime checker. It also fixes issue [8846](https://trac.cppcheck.net/ticket/8846 ):
```cpp
int * f(int a[])
{
return a;
}
```
2018-11-17 09:41:59 +01:00
Paul Fultz II
d376e9f245
Track variable lifetime through function calls ( #1481 )
2018-11-16 06:12:28 +01:00
Daniel Marjamäki
5d086d60ad
Fixed #8844 (snd: Wrong varid and ast)
2018-11-14 21:05:09 +01:00
Daniel Marjamäki
69f2e0938a
VarId: Improved varids for struct members ( #8844 )
2018-11-14 19:11:35 +01:00
Daniel Marjamäki
39c04b650d
astyle formatting
...
[ci skip]
2018-11-14 19:10:52 +01:00
Daniel Marjamäki
69f6100d83
Fixed #8339 (false positive: unread variable despite delete is used on it)
2018-11-14 17:04:21 +01:00
Paul Fultz II
54453c5802
Fix FP when copying pointer to string ( #1479 )
2018-11-14 06:59:25 +01:00
Daniel Marjamäki
ac242b69d6
Refactoring: Use range for loops
2018-11-14 06:58:21 +01:00
Paul Fultz II
f0c86b9d14
Fix issue 8842: Crash in valueFlowTerminatingCondition on incomplete code ( #1480 )
2018-11-14 06:23:45 +01:00
Paul Fultz II
e839001f3d
Fix warnings ( #1478 )
2018-11-14 06:14:04 +01:00
Daniel Marjamäki
d97851b9db
change severity for 'unknown macro' to error for now.
2018-11-13 21:08:45 +01:00
Daniel Marjamäki
152be6df63
Report 'unknown macro' as information message with id unknownMacro
2018-11-13 20:14:56 +01:00
Daniel Marjamäki
a50eb56d8d
Extend 'Unknown macro' check
2018-11-13 18:30:40 +01:00
Daniel Marjamäki
e6a5e0f752
Warn when there is a unknown macro
2018-11-13 16:49:15 +01:00
Daniel Marjamäki
69e7392ce2
Fixed #8449 (False positive 'constStatement' when initializing std::unordered_map)
2018-11-12 18:10:34 +01:00
Daniel Marjamäki
3d629944da
Fixed #8100 (False positive when method/function defines lambda with pointer return value)
2018-11-12 11:28:38 +01:00
Daniel Marjamäki
f096d7f474
astyle formatting
...
[ci skip]
2018-11-12 10:08:57 +01:00
Paul Fultz II
0e11bb07c8
Extend lifetime analysis to pointer usage ( #1477 )
...
* Use lifetime analysis for pointers as well
* Fix issue 1143: Pointer to local array
* Update message when using pointers
* Avoid infinite loop in tracing lifetimes
2018-11-12 10:08:17 +01:00
Daniel Marjamäki
717a2d370c
astyle formatting
...
[ci skip]
2018-11-12 06:32:02 +01:00
Daniel Marjamäki
58882b1f14
Fixed #8261 (False positive "Statements following return, break, continue, goto or throw will never be executed.")
2018-11-12 06:31:17 +01:00
Paul Fultz II
5bda102897
Fix warnings ( #1476 )
2018-11-12 06:08:57 +01:00
Paul Fultz II
68d6b96878
Diagnose invalid lifetimes ( #1475 )
...
* Add check for invalid lifetimes
* Fix FP with member variables
* Dont forward lifetime values in subfunction
* Update message to use out of scope
2018-11-11 16:43:54 +01:00
Daniel Marjamäki
bdd4623124
valueFlowLibraryFunction: fix crash found with daca@home
2018-11-11 16:41:01 +01:00
Daniel Marjamäki
3f55707b30
Fixed #8064 (Taking the address of a moved variable is not accessing it)
2018-11-11 12:47:27 +01:00
Paul Fultz II
e46691597e
Fix issue 8841: FP knownConditionTrueFalse - Dont treat unknown function as noreturn ( #1474 )
...
* Fix issue 8841: Dont treat unknown function as noreturn
* Add a parameter to set default value when the function is unknown
2018-11-11 08:04:01 +01:00
Daniel Marjamäki
ee2dfb6604
Fixed #8058 (False positive returnAddressOfAutoVariable within lambda)
2018-11-11 07:52:38 +01:00
Daniel Marjamäki
93cde415a7
Fixed #7988 (variable in condition gets wrong varid)
2018-11-11 07:50:25 +01:00
Daniel Marjamäki
148f257c6b
Fixed #8838 (False positive on overridden virtual function that is marked both const and final)
2018-11-10 21:57:50 +01:00
Daniel Marjamäki
8327aab127
Fixed #8628 (Wrong AST in case)
2018-11-10 21:32:06 +01:00
Daniel Marjamäki
d5a478d5c5
astyle formatting
...
[ci skip]
2018-11-10 21:30:01 +01:00
Daniel Marjamäki
4cef2e94e7
Fixed #8368 (FP redundantAssignment - assignment has unknown side-effects)
2018-11-10 18:42:13 +01:00
IOBYTE
69e6e11844
Fix a template simplifier namespace bug in #7145 ( #1473 )
...
* Fix a template simplifier namespace bug in #7145
* Refactor template simplifier to only call getTemplateDeclarations once per loop.
2018-11-10 16:41:14 +01:00
Paul Fultz II
1ffcc6b730
Add initial lifetime checker ( #1448 )
...
* Inital valueflow lifetime checker
* Forward values
* Add initial tests
* Fix deplicate messages
* Fix traversing nested lambdas
* Turn test case into a todo
* Skip if returning a container
* Fix FP when using references
* Add missing header
* Fix FP from broken scopes
* Fix FP with static variable
* Add test for more FPs
* Parse lambda functions
* Check for capture by value
* Add tests for using a container and lambda together
* Fix cppcheck errors
* Add test for nextAfterAstRightmostLeaf
* Add valueflow tests
* Update error message
* Check for correct lambda token
* Improve error path reporting
* Fix hang when parsing arrays that look almlost like lambdas
2018-11-10 16:40:40 +01:00
IOBYTE
e302e6e7a1
Fix symbol database argsMatch to skip all redundant type information (class, struct, union, enum) ( #1472 )
2018-11-09 15:54:17 +01:00
rikardfalkeborn
a3e717bea9
Use functions instead of comparing with enum ( #1471 )
...
* Use isComparisonOp() instead of enum
* Use isAssignmentOp() instead of enum
2018-11-09 06:30:41 +01:00
IOBYTE
67fe99fcd9
Fix symbol database argsMatch function and its usage so qualified types are handled properly. ( #1470 )
...
* Fix symbol database argsMatch function and its usage so qualified types are handled properly.
* Remove assert.
2018-11-09 06:11:48 +01:00
Paul Fultz II
36e663e250
Fix issue 8839: FP knownConditionTrueFalse - condition inside a while-clause ( #1469 )
2018-11-09 06:09:51 +01:00
IOBYTE
17a8a4898d
Fix another template simplifier namespace bug. ( #1467 )
...
* Fix another template simplifier namespace bug.
* Add missing forward declarations caused by token bug.
2018-11-07 21:25:42 +01:00
Paul Fultz II
7373be2bfa
Add a pass in valueflow for terminating conditions ( #1323 )
...
* Add valueflow for terminating conditions
* Add valueflow test
* Dont check for same expressions for now to avoid double diagnostics
* Check nesting
* Add more tests
* Ensure conditions happen in order
* Check for null
* Add error path
* Support same expression check as well
* Use early continue
* Skip checking the same token
* Avoid double condtion diagnosis
* Fix FP when in switch statements
* Fix FP when time function
* Skip conditional escapes
* Use simpleMatch
* Fix naming
* Fix typo
2018-11-07 06:49:07 +01:00
Daniel Marjamäki
35d18be311
ValueFlow: Refactoring, removed redundant assignment
2018-11-06 07:02:20 +01:00
IOBYTE
c966f31183
Fixed #8835 (friend class and non-empty constructor: Uninitialized members not reported) ( #1466 )
2018-11-06 06:44:08 +01:00
Daniel Marjamäki
00340efc57
ValueFlow: Refactoring valueFlowCallFunction
2018-11-06 06:38:26 +01:00
IOBYTE
9b67e680ae
Fix template simplifier namespace support. ( #1464 )
2018-11-05 19:55:21 +01:00
Daniel Marjamäki
ca19894a04
ValueFlow: In evaluate handle correlated values
2018-11-05 18:07:35 +01:00
Daniel Marjamäki
da44ce0b5d
ValueFlow: evaluate strlen and char literals better
2018-11-05 16:52:12 +01:00
Daniel Marjamäki
307a19d17e
Refactoring: Use range for loop
2018-11-05 09:49:28 +01:00
IOBYTE
2275f05f65
Fixed #8833 (false negative: No 'return' statement in non-void function causes undefined behavior.) ( #1463 )
2018-11-05 06:55:30 +01:00
Daniel Marjamäki
977fdd88a9
ValueFlow: Fix a few issues in 'evaluate'
2018-11-05 06:53:48 +01:00
Daniel Marjamäki
8a54420274
ValueFlow: Try to handle multiple argument values in <returnValue> evaluation
2018-11-04 20:52:12 +01:00
Daniel Marjamäki
dd9a1e890b
valueFlowRightShift: Do not perform analysis when rhs is negative
2018-11-04 17:13:23 +01:00
Daniel Marjamäki
efd92fd714
Refactoring: reuse utility function in SymbolDatabase
2018-11-04 13:29:29 +01:00
Daniel Marjamäki
6878de2c5e
ValueFlow: getExpressionRange, valueFlowRightShift
2018-11-03 23:25:46 +01:00
Daniel Marjamäki
8a05be34f8
Fix Cppcheck shadow variable warning
2018-11-03 19:41:25 +01:00
Daniel Marjamäki
f8b0584f6a
replace 'constexpr' with 'const'
2018-11-03 19:22:51 +01:00
Daniel Marjamäki
fb76ef1db1
Fixed testrunner
2018-11-03 18:59:55 +01:00
Daniel Marjamäki
66ca03fa0c
Fixed #8826 (false negative: Invalid memory address freed)
2018-11-03 18:55:20 +01:00
Daniel Marjamäki
ef35b86b4a
Multipass Valueflow
2018-11-03 15:53:24 +01:00
Daniel Marjamäki
6138294e3d
Fixed #8818 (AST broken: restrict)
2018-11-03 11:05:38 +01:00
Daniel Marjamäki
9741239b2f
Fixed #8824 (False positive: uninitialized variable (regression))
2018-11-03 10:31:55 +01:00
Armin Müller
acf2035a53
Typos found by running "codespell" ( #1461 )
2018-11-03 07:34:27 +01:00
Daniel Marjamäki
a4afcb5995
Revert "Fixed #8818 (AST broken: restrict)"
...
This reverts commit e7d61f399a
.
2018-11-02 21:07:37 +01:00
Daniel Marjamäki
0cc4555337
Revert "Tokenizer: Do not remove 'constexpr'"
...
This reverts commit 2f400b40ba
.
2018-11-02 21:07:24 +01:00
Daniel Marjamäki
2f400b40ba
Tokenizer: Do not remove 'constexpr'
2018-11-02 20:32:12 +01:00
Daniel Marjamäki
e7d61f399a
Fixed #8818 (AST broken: restrict)
2018-11-02 20:28:49 +01:00
Daniel Marjamäki
614a252704
Fix Match warning
2018-11-02 20:14:34 +01:00
Daniel Marjamäki
5de683ec49
Container size: Fix false positive
2018-11-02 20:10:40 +01:00
Daniel Marjamäki
16cc20a232
ValueFlow: Better handling of container size values
2018-11-02 18:28:32 +01:00
Daniel Marjamäki
3798feecad
TemplateSimplifier : Remove 'class|struct' in template arguments
2018-11-02 14:49:40 +01:00
rikardfalkeborn
869e4ba6ab
Add check for return value of boolean function ( #1451 )
...
* Add check for return value of boolean function
The rule for converting an integer to a boolean is that 0 is mapped to
false and everything else is mapped to true. There is nothing wrong with
the following code (according to the standards):
bool f()
{
return -1;
}
and neither gcc nor clang will warn about it. However, it's a bit
confusing. This commit adds a check that warns when a value other than 0
or 1 is returned from a boolean function (similar to the existing check
that functions with boolean arguments are only passed 0 or 1). Since the
code is perfectly legal, set the severity to "Style".
* Use early continue and remove some braces
* Add testcase with multiple returns
* Avoid null pointer dereference in case of return without operand
* Skip lambdas
Add TODO-test cases that shows FPs when the return type of lambdas are
specified explicitly (this is a problem with findLambdaEndToken).
* Enable testcases
2018-11-01 11:08:16 +01:00
rikardfalkeborn
88008fedb1
findLambdaEndToken handle explicit type ( #1458 )
...
* findLambdaEndToken: Add tests
* Add handling of explicit return in findLambdaEndToken()
* Use AST in findLambdaEndToken()
* Fix ast when lambda is mutable
2018-10-31 12:36:08 +01:00
Paul Fultz II
fafd0742d4
Fix FPs with return conditions ( #1455 )
...
* Fix 8815: FP with identical inner conditions
* Fix issue 8801: FP when not returning a bool
* Fix FP
* Add missing semicolon
* Move returnVar
2018-10-31 09:47:48 +01:00
Daniel Marjamäki
c03d32b429
ValueFlow: Improve containerSize handling of string like classes
2018-10-28 19:14:00 +01:00
Daniel Marjamäki
8beb42cc90
astyle formatting
...
[ci skip]
2018-10-28 17:37:19 +01:00
Paul Fultz II
2b6cc33dc6
Fix issue 8757: Throw syntax error on invalid code ( #1378 )
...
* Fix issue 8757: Throw syntax error on invalid code
* Fix FP with lambda returns
* Remove double percent
* Check more keywords
* Skip preprocessor directives
* Check for valid PP directive
* Fix preprocessor check
* Dont check for preprocessor directives
2018-10-28 17:17:53 +01:00
Paul Fultz II
f5811c6818
Fix issue 8732: Syntax error when using enable_if ( #1453 )
...
* Fix issue 8732: Syntax error when using enable_if
* Fix FPs
* Use simpleMatch
2018-10-28 17:16:31 +01:00
Daniel Marjamäki
06ede9c239
ValueFlow: handle x+=y for containers
2018-10-27 18:38:04 +02:00
IOBYTE
adbbadec7f
Fixed #8798 (template simplifier: wrong simpifications for namespaces) ( #1452 )
2018-10-26 14:20:13 +02:00
Kamil Dudka
d206047b84
Fixed #8794 - Memory leak false positive triggered by !(x != NULL) ( #1450 )
2018-10-26 06:21:45 +02:00
Daniel Marjamäki
86782af43c
Fix Cppcheck warning
2018-10-25 07:15:32 +02:00
Daniel Marjamäki
044c4b7fbb
Refactoring: Use range for loop
2018-10-25 06:14:27 +02:00
Daniel Marjamäki
b8e8b12783
Fixed #8797 (exprDependsOnThis handle method call in non-inline method)
2018-10-24 20:17:00 +02:00
Daniel Marjamäki
2348dcde6c
#8801 : Quick fix for false positives
2018-10-24 19:57:50 +02:00
IOBYTE
ea4e6a60f7
Fix template simplifier from deleting the same declaration multiple times ( #1449 )
...
Found by running valgrind on testrunner. May fix #8808 .
2018-10-24 19:32:37 +02:00
IOBYTE
0763fdbfad
Copy template default argument values from forward declaration to declaration. ( #1447 )
...
It is possible to define default template parameter values in forward
declarations and not define any in the actual declaration. Cppcheck
ignores forward declarations and only uses the default values in the
actual declaration so default values in forward declarations are copied
to the actual declaration when necessary.
2018-10-24 14:38:59 +02:00
Daniel Marjamäki
be1ff268c0
Refactoring: Use range for loops
2018-10-24 11:29:15 +02:00
Daniel Marjamäki
2e4f317c0b
Revert "Remove FIXME"
...
This reverts commit 749699c632
.
2018-10-22 21:03:30 +02:00
Daniel Marjamäki
15160f1691
Fixed #8788 (AST Broken error from assigning lambda to variable)
2018-10-22 17:25:01 +02:00
Daniel Marjamäki
749699c632
Remove FIXME
2018-10-22 12:45:34 +02:00
Daniel Marjamäki
dc38681a56
Remove FIXME in AST validation. Ticket #8749
2018-10-22 11:37:24 +02:00
Daniel Marjamäki
c483bcb12b
Fixed testrunner
2018-10-22 00:28:09 +02:00
Daniel Marjamäki
f9b132e831
Tokenizer::simplifyTypedef: Fix bug with arrays
2018-10-21 21:15:34 +02:00
Daniel Marjamäki
64fbffc90d
astyle formatting
...
[ci skip]
2018-10-21 20:28:46 +02:00
Paul Fultz II
edde0eedaa
Fix FP issue 8801: Condition 'a+b' is always true ( #1444 )
2018-10-21 08:04:00 +02:00
Paul Fultz II
2989c44f59
Enable checking duplicate expressions across associative operators ( #1445 )
...
* Enable checking duplicate expressions across associative operators
* Remove bitshift operators and check for streamRead
2018-10-21 07:09:20 +02:00
Daniel Marjamäki
14afc3fd3a
Fixed #8796 (Tokenizer::simplifyCompoundAssignment: Wrong simplification of return)
2018-10-20 21:33:43 +02:00
Daniel Marjamäki
277e0f1a8f
Fix Cppcheck error message
2018-10-20 15:28:34 +02:00
Daniel Marjamäki
29feaa5a51
Tokenizer: Avoid constant folding
2018-10-20 10:51:50 +02:00
Daniel Marjamäki
d265a0d6ab
Fixed #8798 (SymbolDatabase: Inner unnamed union)
2018-10-20 09:43:08 +02:00