IOBYTE
ce9fdd181d
Add regression test for #9146 (Syntax error on valid C++ code) ( #1867 )
2019-06-02 10:23:47 +02:00
Paul Fultz II
676a241137
Add regression tests for syntax errors ( #1866 )
2019-06-02 10:23:27 +02:00
Paul Fultz II
8a1c0dd017
Fix FP with non-local variable referencing a non-local variable ( #1864 )
2019-06-02 10:21:26 +02:00
Paul Fultz II
6ae7be0f53
Fix FP with lifetime containers ( #1865 )
2019-06-02 10:14:48 +02:00
IOBYTE
bee248b2de
token simplifier: fix namespace, token link and syntax error support for template type aliases ( #1863 )
2019-06-01 10:52:29 +02:00
Daniel Marjamäki
5d10b57b04
Fixed #8997 (False positive redundantAssignment when pointer is updated with +=)
2019-05-31 12:24:31 +02:00
Paul Fultz II
f75c15af56
Fix issue 6821: New check: access heap/stack data using address of variable
...
This fixes errors with:
```cpp
int f() {
int i;
return (&i)[1];
}
```
It uses the lifetime analysis to detect the issues.
2019-05-31 12:24:31 +02:00
Paul Fultz II
108cdaa485
Fix FP with unreadVariable ( #1859 )
2019-05-31 08:06:36 +02:00
Paul Fultz II
33130bdff6
Fix issue 9145: Syntax error on valid C++14 code ( #1860 )
2019-05-31 08:05:01 +02:00
Daniel Marjamäki
66a61fe5e8
SymbolDatabase: Improved findFunction
2019-05-30 20:26:45 +02:00
Daniel Marjamäki
36b6fb9f4d
Fixed #8558 (False portability positive caused by incorrect method resolution)
2019-05-30 19:24:51 +02:00
Daniel Marjamäki
4da50942b0
Fixed #8120 (False positive: Memory pointed to by 'p' is freed twice)
2019-05-30 16:22:41 +02:00
orbitcowboy
55df395a4e
Running astyle [ci skip]
2019-05-30 14:41:14 +02:00
Ken-Patrick
3cdc236e10
Fix false positive with several ! (not) operators ( #1856 )
...
With the following code
int f(int x, int y) {
if (!!(x != 0)) {
return y/x;
}
cppcheck would wrongly warn that there might be a division by zero in
"return y/x;".
2019-05-29 09:45:15 +02:00
IOBYTE
1e7f5010eb
template simplifier: fix expansion of template arguments in default parameter instantiation ( #1857 )
2019-05-28 21:32:37 +02:00
IOBYTE
e8692b012f
template simplifier: partial fix for instantiation of templates with type trait parameters ( #1855 )
2019-05-27 20:51:52 +02:00
Paul Fultz II
312fdf157b
Fix issue 9144: Syntax error with type intrinsics ( #1852 )
...
* Fix issue 9144: Syntax error with type intrinsics
* Only run when using cpp
2019-05-27 06:54:21 +02:00
Paul Fultz II
61935802d1
Fix issue 9141: Syntax error ( #1853 )
2019-05-27 06:50:43 +02:00
orbitcowboy
02d307a231
posix.cfg: Added partial support for scandir() and a TODO comment.
2019-05-25 23:32:28 +02:00
orbitcowboy
4d223a70dc
MathLib: Added robustness tests for 'MathLib::divide()'.
2019-05-25 23:06:50 +02:00
Paul Fultz II
cb7f925f5e
Fix issue 9109: Syntax error for valid C++ code
2019-05-24 10:44:08 +02:00
IOBYTE
5efb23ffff
template simplifier: fix instantiation of variadic template with no arguments ( #1848 )
...
* template simplifier: fix instantiation of variadic template with no arguments
* fix white space change
* add support for <class...>
* add variadic template flag
2019-05-23 20:53:26 +02:00
Daniel Marjamäki
cd05f4eefc
test/cli/test-helloworld: Fix misra warning 17.7
2019-05-23 14:31:55 +02:00
Daniel Marjamäki
de4a33167d
astyle formatting
...
[ci skip]
2019-05-21 10:43:33 +02:00
Paul Fultz II
9838bfa79f
Fix false positive in constArgument when passing struct member ( #1845 )
2019-05-21 10:41:16 +02:00
Paul Fultz II
9949ae1b4f
Fix issue 8995: False Positive: Redundant code with initializer-list created object ( #1844 )
2019-05-21 10:40:36 +02:00
Paul Fultz II
9055682fdc
Fix synax error in issue 9057 and 9138 ( #1843 )
2019-05-21 08:47:10 +02:00
Daniel Marjamäki
29e5992e51
Fixed #9045 (FP operatorEqRetRefThis - recent regression)
2019-05-20 21:30:20 +02:00
IOBYTE
592ff56b90
template simplifier: fix single parameter template with default value ( #1842 )
...
* template simplifier: fix single parameter template with default value
* fix derived class with single default argument
2019-05-19 19:19:57 +02:00
Paul Fultz II
ce96ec2773
Fix issue 9136: Syntax error on valid C++14 code: createLinks2() failed
2019-05-19 19:06:12 +02:00
Paul Fultz II
8cbd9b03aa
Fix issue 8890: AST broken calling member function from templated base class ( #1836 )
...
* Fix issue 8890: AST broken calling member function from templated base class
* Format
* Check for double bracket
* Add test to createLinks2
* Remove extra test
* Reduce test case for links
2019-05-19 10:05:34 +02:00
Rikard Falkeborn
ada881ccdf
Fix #9130 (FP memory leak with NULL pointer cast) ( #1839 )
2019-05-18 06:22:25 +02:00
Paul Fultz II
cf3515ee61
Fix issue 7372: False positive uninitMemberVar - on template specialization
...
This fixes the issue by skipping diagnostics when the symbols are incomplete in the constructor.
2019-05-17 20:24:41 +02:00
orbitcowboy
4a9176f83c
std.cfg: Added a test for tmpfile().
2019-05-17 16:02:48 +02:00
Daniel Marjamäki
e80181d35a
astyle formatting
...
[ci skip]
2019-05-17 09:32:14 +02:00
Daniel Marjamäki
57c6628732
Revert 'Cleaning up unsimplified templates'. This fix caused problems.
2019-05-16 21:11:04 +02:00
orbitcowboy
e48d785ea4
gnu.cfg: Added tests for mkostemp(), mkstemps() and mkostemps() functions. The test script 'test/cfg/runtests.sh' is now loading posix.cfg when checking gnu.cfg. Otherwise 'close()' was not available to Cppcheck, which lead to an error when 'make checkcfg' was executed.
2019-05-16 17:49:33 +02:00
orbitcowboy
719eb25ba9
posix.cfg: Improved configuration for 'mkstemp()' and added test cases to ensure resource leaks are caught.
2019-05-16 15:53:22 +02:00
Daniel Marjamäki
0144db2490
Fixed 'Syntax Error' when < link is not set properly
2019-05-15 21:34:56 +02:00
Daniel Marjamäki
2e7725dfa7
Fix test case, my change is reverted
2019-05-15 07:06:04 +02:00
Daniel Marjamäki
79bb22f038
Fixed #9131 (Tokenizer::createLinks2; using std::list; list<config_option*> stack;)
2019-05-14 20:30:02 +02:00
Paul Fultz II
4e94c64da8
Fix issue 9099 and 9102: Incorrect valueflow for global variables ( #1832 )
2019-05-14 08:58:27 +02:00
Paul Fultz II
195da2b3d2
Fix issue 8993: False positive duplicateCondition related to auto ( #1831 )
2019-05-14 08:57:36 +02:00
Rikard Falkeborn
dc0e8c214e
Fix #9128 (FP in return non bool with class declared in function) ( #1830 )
...
Also break up the tests to smaller tests.
2019-05-14 08:56:28 +02:00
Daniel Marjamäki
9f00149674
Fixed #9127 (ast: wrong ast after using and template instantiation)
2019-05-12 17:24:42 +02:00
Daniel Marjamäki
27fad38e00
Fixed #9084 (Tokenizer::setVarId: Same varid for member variable and argument, unknown template type)
2019-05-12 09:10:37 +02:00
Daniel Marjamäki
4d9b1e6c3d
Fixed #9094 (Tokenizer::createLinks2 problem with 'x%x<--a==x>x')
2019-05-11 19:11:40 +02:00
Daniel Marjamäki
1e2f1bac1f
Fixed #8921 (Broken AST - mem = (void*)(new char))
2019-05-11 15:50:30 +02:00
Daniel Marjamäki
d58d4273f9
Cleaning up unsimplified templates
2019-05-11 13:00:03 +02:00
IOBYTE
eade2bb2c2
Add support for simplifying user defined literal operator. ( #1827 )
2019-05-09 09:52:18 +02:00
Daniel Marjamäki
e4c178d5c0
bump simplecpp
2019-05-07 19:15:31 +02:00
IOBYTE
baeae95bac
template simplifier: fix a template alias TODO test ( #1823 )
2019-05-06 19:06:46 +02:00
Daniel Marjamäki
f6527fcd9b
fixed tests, unused templates are removed by default
2019-05-05 19:40:58 +02:00
Daniel Marjamäki
9947774ab7
Removed test case with unused templates
2019-05-05 19:15:42 +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
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
5e9b7a6749
Cleanup AST tests. The best would be if 'operators' in declarations was not included at all in the AST.
2019-05-04 07:31:59 +02:00
Daniel Marjamäki
7900902ad9
Renamed 1-helloworld helloworld
2019-05-03 20:22:35 +02:00
Daniel Marjamäki
e8c0345a51
Fixed #7999 (Inline suppressions do not work under weird circumstances)
2019-05-03 20:19:28 +02:00
Daniel Marjamäki
bbb5bfd432
Preprocessor: Test case has been moved to simplecpp
2019-05-03 19:27:08 +02:00
Sebastian
b1cb03b560
posix.c: Add test to avoid regression of already fixed ticket #9118 ( #1820 )
...
Trac ticket: https://trac.cppcheck.net/ticket/9118
Commit that likely fixed it already:
1b74bca973
2019-05-03 16:35:15 +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
Rikard Falkeborn
68869438be
Refactoring: Use range based for loops ( #1817 )
2019-05-02 06:53:07 +02:00
Daniel Marjamäki
202d38b9eb
Revert "Fixed #7999 (Inline suppressions do not work under weird circumstances)"
...
This reverts commit 0cc41f44b8
.
2019-05-02 06:50:08 +02:00
Daniel Marjamäki
0cc41f44b8
Fixed #7999 (Inline suppressions do not work under weird circumstances)
2019-05-01 20:37:36 +02:00
Daniel Marjamäki
c4c847b952
Remove test case, ValueFlow will truncate and sign-extend values
2019-05-01 19:33:47 +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
7260bdd6d8
Fixed Cppcheck shadowVar warnings
2019-04-30 21:01:18 +02:00
Daniel Marjamäki
66064fb2bb
Disable valueFlowGlobalConstVar until #9099 is fixed
2019-04-30 20:51:59 +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
Daniel Marjamäki
37656cdca1
Fix comment
2019-04-30 08:54:41 +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
0e8f2cdf63
Use multiline in testing
2019-04-28 07:48:38 +02:00
Daniel Marjamäki
004d7d5333
Fixed #8580 (False positive: unused function (lambda))
2019-04-27 17:17:51 +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
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
Rikard Falkeborn
0ca217daef
TestToken: Add more tests ( #1806 )
2019-04-25 07:08:13 +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
Armin Müller
b59d7e2f35
Typos found by running "codespell" ( #1804 )
2019-04-23 13:26:48 +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
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
orbitcowboy
45a3f679b4
posix.cfg: Improved configuration for close(). Issue a warning in case close is called with a file pointer having a negative value.
2019-04-21 12:28:17 +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
amai2012
361fc44005
Adjust more test results for invalid code
2019-04-19 20:53:07 +02:00
amai2012
ebe7783493
Adjust some test results for invalid code. Comment out still crashing example for #8913
2019-04-19 17:42:21 +02:00
amai2012
28bc3cad92
#8913 SIGSEGV in CheckUnusedVar::checkFunctionVariableUsage - C++/CLI code
2019-04-19 13:55:25 +02:00