Commit Graph

9200 Commits

Author SHA1 Message Date
Daniel Marjamäki 3066c0653c Fixed #8668 (SymbolDatabase: Wrong findFunction match for const pointer argument) 2019-07-29 18:14:23 +02:00
Daniel Marjamäki 607b3daca8 ValueFlow: Improve bailout for structs etc in loops 2019-07-29 15:51:48 +02:00
Daniel Marjamäki a1214348c0 Fixed #8974 (false negative regression about never used variable) 2019-07-29 08:49:19 +02:00
Daniel Marjamäki 602911cfca Activate a TODO test case 2019-07-29 08:06:57 +02:00
Daniel Marjamäki a178d05cc5 Changed TODO test case, I do not see why it should warn. 2019-07-29 07:51:00 +02:00
IOBYTE 07ac6c5f08 Fix ternary operator simplification to accept template parameters. (#2048)
Also simplify decltype of bool and numeric literals in template
arguments.
2019-07-28 21:52:52 +02:00
IOBYTE badc573b80 Fix #9224 (Performance regression in template parsing: 250x - 1200x slower) (#2046) 2019-07-28 09:25:18 +02:00
Daniel Marjamäki e8ec6e6f11 Fixed #8349 (Noisy nullPointerRedundantCheck) 2019-07-27 20:03:06 +02:00
Daniel Marjamäki 1c75257212 Token::hasKnownIntValue: Fix when there is one possible int value and one known BUFFER_SIZE value, it should return false. 2019-07-27 08:25:07 +02:00
Rikard Falkeborn f95d193e22 Fix #8282 (memleak FP when returning std::pair) (#2039) 2019-07-26 07:03:58 +02:00
Paul Fultz II ee28a45db4 Fix issue 9235: new crash in astutils isVariableChanged from endless recursion (#2040) 2019-07-26 07:03:21 +02:00
Paul Fultz II b049fd9303 Improve propogation of lifetimes of function arguments
This will now warn for cases like this:

```cpp
int* f(int * x) {
    return x;
}
int * g(int x) {
    return f(&x);
}
````
2019-07-26 07:02:07 +02:00
Rikard Falkeborn a69a570505 Fix FP leakVarNotUsed with freopen() and stdin (#2034)
One usecase for freopen() is to redirect input and output streams to
files. For that, the return value is not needed.
2019-07-25 21:09:23 +02:00
Paul Fultz II 744a94ad5a Fix issue 9231: FP constParameter - argument passed parent ctor (#2032) 2019-07-24 20:59:58 +02:00
IOBYTE 999d2f797c Fix #9225 (Crash on valid C++14 code) (#2031)
* Fix #9225 (Crash on valid C++14 code)

This only fixes the crash. Specialization of nested templates is still
broken.

* fix cppcheck warnings

* fixed another cppcheck warning
2019-07-24 19:20:19 +02:00
Daniel Marjamäki bbcffce529 Fixed #9062 (False positive "condition is always true") 2019-07-24 19:16:35 +02:00
Daniel Marjamäki e11dcc609b Fixed #7758 (Function array is seen as Uninitialized) 2019-07-24 18:20:23 +02:00
Daniel Marjamäki 7c0b011c05 Fixed #9230 (Improve check: integer conversion overflow in return) 2019-07-24 16:17:52 +02:00
Daniel Marjamäki 2da75d5af4 Split up Cppcheck attribute. low and high values can be specified separately and they can be used for variables also. 2019-07-24 15:08:26 +02:00
Daniel Marjamäki cab9f61b79 safe checks: Handle float parameters 2019-07-24 12:09:13 +02:00
Daniel Marjamäki 10be2a1941 Safe checks: container parameters 2019-07-24 11:39:35 +02:00
Daniel Marjamäki 8959c5a9d0 Rename valueFlowAllFunctionParameterValues => valueFlowSafeFunctionParameterValues 2019-07-24 10:57:35 +02:00
Paul Fultz II bb52a63c4e Add check for const variables
When a local reference is declared, this will check if that local reference can be declared as `const`.
2019-07-24 09:59:01 +02:00
Paul Fultz II 3ec3bd52e0 Fix FP when using a pointer to a container (#2029) 2019-07-24 00:04:49 +02:00
Paul Fultz II ab0fcc7640 Fix issue 9216: reset() method confusion (#2025)
* Fix issue 9216 with smart pointer reset

* Check for arrow
2019-07-23 22:45:58 +02:00
Paul Fultz II 60b670babd Fix issue 9219: False positive, returnDanglingLifetime (#2026)
* Check for pointer deref for container methods

* Formatting
2019-07-23 21:59:05 +02:00
IOBYTE 5ad5cfcc29 Fix #9217 (Regression: Memory explodes in simplifyTemplateAliases) (#2021)
* Fix #9217 (Regression: Memory explodes in simplifyTemplateAliases)

* fix use after free when nothing was copied
2019-07-23 21:28:24 +02:00
Daniel Marjamäki 4fb6c27276 Modernize: Use enum class 2019-07-23 14:29:02 +02:00
Daniel Marjamäki c8bc88e7e2 Fix compiler error 2019-07-23 13:14:08 +02:00
Rikard Falkeborn 8cd1d5a47d Use library for memleak checks (#2002)
* Use library for memleak checks

Change memleakOnRealloc and leakReturnValNotUsed to use library
configuration instead of hardcoding "realloc".

In order to do so, some care needs to be taken when matching for a
reallocation function, since it can no longer be assumed that the input
to be allocated is the first argument of the function. This complicates
getReallocationType() and checkReallocUsage() but is necessary in order
to handle for example freopen() properly.

Also, refactor memleakOnRealloc check to reduce duplicated code when
checking "a" and "*a". When doing so, extending the check to look for
arbitrary number of "*" can be done for free (just change an if
statement to a while statement). Most likely, this is an unusual case in
real world code.

* Remove redundant whitespace in Token::Match()

* Run on simplified checks

* Fix cppcheck warning
2019-07-22 10:37:36 +02:00
Rikard Falkeborn 06337cedf5 Run more tests on full token list (#2020)
Since all checks are run on the full token list and not the simplified
one, run the tests on the full token list as well.
2019-07-22 10:26:55 +02:00
Rikard Falkeborn abea580b78 Fix FP memory leak with unknown function call in condition (#2012)
* Fix FP memory leak with unknown function call in condition

This was introduced in 8513fb81d2 when
fixing memory leaks for global variables allocated in condition. The
refactored code had an inconsistency where c and c++ code behaved
slightly differently when `var` is NULL. This seemed to not have an
impact as the code was written prior to 8513fb81d2,
but when the same code was used for conditions, FPs were introduced.

The introduced FPs were memleak warnings when there should have been an
information message about missing configurations for code like

	void f() {
		char *p = malloc(10);
		if (set_data(p)) {}
	}

Fix this by always returning true if varTok->Variable() is NULL for
both c and c++ code.

* Improve function name
2019-07-18 15:23:19 +02:00
Paul Fultz II a08a9c1349 Switch to use lifetime analysis for iterators and pointers to invalid containers
This will diagnose more issues such as:

```cpp
void f(std::vector<int> &v) {
    auto v0 = v.begin();
    v.push_back(123);
    std::cout << *v0 << std::endl;
}
```
2019-07-18 10:56:44 +02:00
Daniel Marjamäki 421a8da6a8 Try to clarify signConversion message 2019-07-17 22:41:24 +02:00
Daniel Marjamäki d11d6f112e Detect shadowed arguments 2019-07-17 17:08:42 +02:00
Daniel Marjamäki 90a215af0e Rephraze performance message. /would be faster/could be faster/ to indicate that Cppcheck is not _sure_ that it would be faster 2019-07-17 16:06:10 +02:00
Daniel Marjamäki 64ef879ebf Fix syntaxError for struct initialization 2019-07-17 15:21:17 +02:00
Daniel Marjamäki 9973db3a71 Modernize: Use enum class for Library::Action and Library::Yield 2019-07-17 11:39:30 +02:00
Daniel Marjamäki 5800692fa1 Move and refactor the CheckMemoryLeak::isclass 2019-07-17 08:59:09 +02:00
Rikard Falkeborn 8513fb81d2 Fix #9206 (FP with global variable allocated in condition) (#2007) 2019-07-17 07:43:07 +02:00
Daniel Marjamäki b3688f22e8 Unknown macro: Detect and warn about unknown macro before throw/return 2019-07-16 20:32:46 +02:00
Daniel Marjamäki 5a6b89100d Removed casts 2019-07-16 09:14:44 +02:00
Rikard Falkeborn e19068504d Configure xrealloc and adjust gnu memory functions (#2003)
Remove <noreturn> tag, since the functions do not return unless there
was no error.
2019-07-16 08:12:21 +02:00
Rikard Falkeborn dcc375ca64 Update gtk memory functions (#2000)
* Improve configuration of g_try_realloc and g_try_realloc_n
* Mark g_realloc and similar functions as realloc functions
* Remove g_new, g_new0, etc as <alloc> functions, these are defined as
  macros and handled as the functions they're expanded to.
* Add tests. TODO tests will be resolved by using the library
  configuration in the checker.
2019-07-15 14:51:58 +02:00
IOBYTE 6d6bb31926 fix crash in daca gcc-avr from intentional bad instantiation test (#1994)
* fix crash in daca gcc-avr from intentional bad instantiation test

* fix cppcheck warning
2019-07-15 12:41:06 +02:00
IOBYTE c2ccfd5f8b Increase Windows stack size to 8M (#1998)
* Increase Windows stack size to 8M

* try to add stack size cmake
2019-07-15 12:39:58 +02:00
Daniel Marjamäki af051a3787 astyle formatting
[ci skip]
2019-07-15 09:29:47 +02:00
Denis 68e6a440ff Fix adding unescaped slash token when splitting gcc case range. (#1987)
* Fix adding unescaped slash token when splitting gcc case range.

Construction like case '!'...'~' converted to a list of separate case
tokens. When slas '\' symbol appears as a part of this list it was added
"as is", but it should be escaped like '\\' to be valid c++ code.

* Add test for switch-case range with slash
2019-07-15 09:29:31 +02:00
Daniel Marjamäki d2284ddbcd Fix false positives in self check: Variable t is assigned a value that is never used. Classes with destructors was not handled properly. 2019-07-14 16:20:45 +02:00
Daniel Marjamäki 1cadd9398a Fixed #8933 (false negative: (style) Variable is assigned a value that is never used (std::string)) 2019-07-14 09:44:30 +02:00