9311 Commits

Author SHA1 Message Date
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 0edf0b562855f0c6d5569a3995cb380ed1d5fc6e.

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 2a4be5ae1c466376351b82fcfeadb4b79c877575.

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 3f1e2b42700a1eb1466d4200eb87265defd962f6
(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