Commit Graph

9164 Commits

Author SHA1 Message Date
IOBYTE 5642778206 Fixed #9193 (functionStatic false positive (inconclusive)) (#1943) 2019-07-02 11:40:57 +02:00
IOBYTE bf4e1ef790 template simplifier: consistently handle templates with no arguments (#1939)
this fixes daca boost1.67 crashes
2019-07-01 07:01:14 +02:00
Daniel Marjamäki 0eedcfc160 Fixed #7464 (warn about opposite if and else-if conditions) 2019-06-30 23:26:49 +02:00
Scott Furry a195477470 Correct Zero/Null as pointer constant (#1938)
Building with enhanced clang warnings indicated a large number of
instances with the warning:

`warning: zero as null pointer constant`

Recommended practice in C++11 is to use `nullptr` as value for
a NULL or empty pointer value. All instances where this warning
was encountered were corrected in this commit.

Where warning was encountered in dependency code (i.e. external library)
no chnages were made. Patching will be offered upstream.
2019-06-30 21:39:22 +02:00
Daniel Marjamäki 56df6169fb Fixed #8356 (ValueFlow: variable is not changed in for loop) 2019-06-30 17:50:35 +02:00
Rikard Falkeborn d1d622b74c Valueflow: support global static const variables (#1861) 2019-06-29 14:33:55 +02:00
Daniel Marjamäki 84cc09d17c Update Copyright 2019-06-29 07:49:14 +02:00
Rikard Falkeborn 0d69a86bf8 Remove debug printout (#1933) 2019-06-28 22:08:32 +02:00
IOBYTE 8b347aed42 Fixed #8663 (Stack overflow with template disambiguator) (#1932) 2019-06-28 22:07:21 +02:00
IOBYTE 16788df055 template simplifier: various small fixes (#1916)
* fix adding instantiation of first argument to an instantiation

* add support for function pointer template variables

* fix more cases where templates ending in ">>" are changed to end in "> >"

* fix travis build

* standard types can't be a template parameter name

* remove redundant level == 0 checks

* fix lambda in template variable

* fix a test
2019-06-28 11:14:20 +02:00
Ken-Patrick 927d139488 Fix FP #9165 (#1928)
Properly check the type of the expressions, instead of using the type
of the tokens
2019-06-27 07:48:44 +02:00
Sebastian d745dcc0eb
gtk.cfg: Add g_error_*() functions (#1922) 2019-06-25 19:19:10 +02:00
Paul Fultz II 66e0f06494 Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find (#1912)
* Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find

* Use simpleMatch
2019-06-24 18:52:17 +02:00
Daniel Marjamäki 175070ca50 Revert "Fixed #8938 (FP identicalInnerCondition)"
This reverts commit 0edf0b5628.

This bailout seems to cause many false negatives
2019-06-22 21:57:19 +02:00
Daniel Marjamäki de9c999d79 Better handling of spaces in paths 2019-06-22 19:20:15 +02:00
Daniel Marjamäki 7ceb51a952 Try to improve 'clarifyStatement' warning message 2019-06-22 08:44:41 +02:00
Daniel Marjamäki 16bed07c60 Clarify tests 2019-06-22 07:50:43 +02:00
Daniel Marjamäki cf79830afd Revert "Remove bailout. It hides lots of warnings for real code to avoid FP in unused templates."
This reverts commit 2a4be5ae1c.

When I look at daca@home now there are still lots of false negatives. So this bailout did not cause as much false negatives as I thought.
2019-06-19 22:29:00 +02:00
Ken-Patrick 44d6066c6f FP on assignment through pointer (#1887)
* Fix FP when assigning through pointers

* Add test case for false positive

cppcheck would faulty warn:
"Condition '*b>0' is always true"
2019-06-17 21:25:15 +02:00
IOBYTE 246576fceb Fixed #9178 (Assertion `brackets1.empty() == false' failed on valid C++ code) (#1905)
This fixes a nasty intrinsics related bug causing instantiations that
shouldn't happen.
2019-06-17 21:18:27 +02:00
Rikard Falkeborn b1c8d81bcc Refactoring; Use range for loop (#1900) 2019-06-17 13:17:45 +02:00
Daniel Marjamäki 2a4be5ae1c Remove bailout. It hides lots of warnings for real code to avoid FP in unused templates. 2019-06-16 19:01:45 +02:00
Rikard Falkeborn d909ac8565 Bugfix buffer size for strdup like functions (#1893)
strdup() allocates the string length plus one for a terminating null
character. Add one to compensate for this.

Fixes false positive buffer out of bounds on code like this:

	void f() {
		const char *a = "abcd";
		char * b = strdup(a);
		printf("%c", b[4]); // prints the terminating null character
		free(b);
	}

Also, add a testcase for valueFlowDynamicBufferSize() and add tests for
strdup(), malloc() and calloc().
2019-06-16 16:02:27 +02:00
Ken-Patrick 66ebc187f6 Cleanup some const_cast of Token* (#1886)
* Add non const version of some methods of Token

The aim is to reduce the (ab)use of const_cast.

* Cleanup some more const_cast in valueflow

* Remove useless const_cast

* Remove some const_cast from templatesimplifier

* Remove some const_cast from valueflow
2019-06-16 10:09:38 +02:00
Daniel Marjamäki 6d982d4320 Testing: comment/naming 2019-06-15 13:01:34 +02:00
Rikard Falkeborn b970606c93 Add regression test for #7798 (#1847)
Trac ticket #7798 was fixed in 3f1e2b4270
(More conservative fallback for function overload matching). Add a test
to avoid regressions.
2019-06-15 11:34:06 +02:00
Paul Fultz II b466415bb4 Fix syntax error in issue 9155 (#1885) 2019-06-15 09:48:22 +02:00
IOBYTE 75720528b0 template simplifier: add 2 new template parameter simplifications (#1884)
* template simplifier: add 2 new template parameter simplifications

int{} -> 0
decltype(int{}) -> int

This fixes reduced test cases like #9153.  I'm not sure they will help
real world code that much.

It was necessary to increase the pass count to 4 to get #9153 completly
simplified.

* relax decltype(type{}) simplification to any type
2019-06-15 09:46:32 +02:00
IOBYTE c0d8990e8b Fix up a few more cases where templates ending in ">>" should be changed to end in "> >". (#1883) 2019-06-13 13:37:55 +02:00
IOBYTE 2a4b28c267 Fixed #9155 (Syntax error on valid C++ code) (#1880)
Refactored simplifyTemplateAliases to iterate over template type aliases
rather than instantiations. This fixed template type aliases that were
not templates.

Don't instantiate templates in template type aliases. They will get
instantiated once the type alias is instantiated. This required
increasing the template simplifier pass count to 3 so one of the
existing tests continued to work.
2019-06-12 07:44:48 +02:00
Paul Fultz II b863c18e1d Fix crash in issue 9007 (#1878) 2019-06-10 08:24:09 +02:00
Paul Fultz II 169510bd3a Fix issue 9171: Endless recursion (#1877) 2019-06-10 08:22:48 +02:00
IOBYTE 5af8beecf6 template simplifier: specialized member class not recognized causing wrong instantiation (#1876)
Specialized member classes declared outsize the class were not
recognized. This caused the the member class to be instantiated rather
than the specialized class. We already had a test for this but it was
wrong so it went unnoticed.
2019-06-09 08:11:59 +02:00
Paul Fultz II 1f24aa778b Fix issue 9156: Analysis failed because square brackets arent linked correctly (#1871) 2019-06-09 08:10:57 +02:00
IOBYTE 7a87786cbc template simplifier: class or typename can't be a name (#1875)
* template simplifier: class or typename can't be a name

* struct can't be a name
2019-06-08 07:27:53 +02:00
IOBYTE f02e45bf3d fix syntax error for std::literals::complex_literals::operator""if (#1870) 2019-06-05 10:15:22 +02:00
IOBYTE 41cf865947 template simplifier: add links to expanded return type in function forward declaration (#1868)
This crash was seen in daca capnproto but I could only get creduce to
generate garbage code so the test is in checkgarbage.
2019-06-03 07:06:04 +02:00
Daniel Marjamäki 7ca35d181b uninitStructMember: Fixed FP shown in daca@home 2019-06-02 20:19:53 +02:00
Daniel Marjamäki 7a3302b3e3 CheckLeakAutoVar: Fixed FP seen in daca@home 2019-06-02 15:25:54 +02:00
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