Commit Graph

10996 Commits

Author SHA1 Message Date
Daniel Marjamäki 4fb6c27276 Modernize: Use enum class 2019-07-23 14:29:02 +02:00
Daniel Marjamäki 680fbfe612 Fix Cppcheck warning, unused value 2019-07-23 14:10:34 +02:00
Daniel Marjamäki 681bd0a911 GUI: Better settings for extended safe checks 2019-07-23 11:54:38 +02:00
Daniel Marjamäki 74bd2aa680 Use range for loop 2019-07-22 12:24:16 +02:00
Daniel Marjamäki a81c39af09 Replace 'unsigned' with 'nonneg' 2019-07-22 11:25:51 +02:00
Daniel Marjamäki 7ed3db7b32 astyle formatting
[ci skip]
2019-07-22 10:38:17 +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 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 8cd8a2671c Fix issue 9211: No error on divide by zero outside template instatiation
I am not sure how to add a test for this.
2019-07-18 14:55:30 +02:00
Daniel Marjamäki 28e5133f50 Refactoring: Use range for loop 2019-07-18 14:55:01 +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 f0aeb845e5 ValueFlow: Clarify warnings when argument min/max values are used 2019-07-17 22:17:34 +02:00
Daniel Marjamäki d11d6f112e Detect shadowed arguments 2019-07-17 17:08:42 +02:00
Daniel Marjamäki 0be78bbde6 Rename fileInd to fileIndex 2019-07-17 16:28:47 +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 ec4d68e231 Modernize: use enum class 2019-07-17 10:43:18 +02:00
Daniel Marjamäki 2afd5f5dd0 Modernize: Use enum class 2019-07-17 10:39:06 +02:00
Daniel Marjamäki b15e6801a4 Replace 'unsigned' with 'nonneg' in tokenizer 2019-07-17 10:36:49 +02:00
Daniel Marjamäki e9b12b1fe0 Replace 'unsigned' with 'nonneg' 2019-07-17 10:14:25 +02:00
Daniel Marjamäki e124b31334 Replace 'unsigned' with 'nonneg' 2019-07-17 09:11:42 +02:00
Daniel Marjamäki c04f31a2c2 Refactoring: Use common function 2019-07-17 09:04:42 +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 b4a05a3dd0 Refactoring: Use enum class 2019-07-16 11:12:35 +02:00
Daniel Marjamäki 32eda27391 Refactoring: Use enum class 2019-07-16 10:51:26 +02:00
versat 4e89b13adf checkio.cpp: Fix forgotten "nonneg" change which breaks build 2019-07-16 09:30:36 +02:00
Daniel Marjamäki 7a4a9eba4b remove cast 2019-07-16 09:28:48 +02:00
Daniel Marjamäki ef73a10e30 Replace 'unsigned' with 'nonneg' in checkother 2019-07-16 09:10:10 +02:00
Daniel Marjamäki 3637c486c4 Replace 'unsigned' with 'nonneg' in checkclass 2019-07-16 09:03:45 +02:00
Daniel Marjamäki e877683f01 Replace 'unsigned' with 'nonneg' in checkleakautovar 2019-07-16 08:54:21 +02:00
Daniel Marjamäki c57d3e069a Replace 'unsigned' with 'nonneg' in checkfunctions 2019-07-16 08:49:02 +02:00
Daniel Marjamäki a038ba7dce replace 'unsigned' with 'nonneg' in checkio 2019-07-16 08:37:26 +02:00
Daniel Marjamäki 5dc4f44091 Replace 'unsigned' with 'nonneg' in checkcondition 2019-07-16 08:21:25 +02:00
Daniel Marjamäki 1888b39314 Use 'nonneg' instead of 'unsigned' in checkbufferoverrun 2019-07-16 07:59:35 +02:00
Daniel Marjamäki 5eff1b0f4a Replace 'unsigned' with 'nonneg' in checkstl 2019-07-15 14:05:23 +02:00
Daniel Marjamäki 38182bf37b Replace 'unsigned' with 'nonneg' in valueflow 2019-07-15 13:47:17 +02:00
Daniel Marjamäki 5175bda774 Use 'nonneg' instead of 'unsigned' in checkautovariables 2019-07-15 13:33:29 +02:00
Daniel Marjamäki 4122b2111f astyle formatting
[ci skip]
2019-07-15 12:56:44 +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 aeefaf7004 Travis: Fix one more 'nonneg' issue 2019-07-14 22:49:37 +02:00
Daniel Marjamäki b30ef3d050 Fix wrong 'nonneg' 2019-07-14 17:31:26 +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 534659e596 Avoid 'unsigned' in Tokenizer. Use 'nonneg' instead for arguments and members. 2019-07-14 15:48:20 +02:00
Daniel Marjamäki 0014fe880e Mark members and arguments with 'nonneg' 2019-07-14 12:22:33 +02:00
Daniel Marjamäki 36d7e8a361 Add 'nonneg' macro 2019-07-14 11:40:44 +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
Daniel Marjamäki cf06acae08 Fixed #5995 (False negative selfAssignment regression from 1.65) 2019-07-13 21:45:54 +02:00
Daniel Marjamäki 49dd2deef1 Avoid 'unsigned' in ctu 2019-07-13 20:31:50 +02:00
Daniel Marjamäki e489d9a40f Fix bug. Used wrong ValueType in smart pointer handling 2019-07-13 20:29:15 +02:00
Daniel Marjamäki 5d853bcb58 Avoid 'unsigned' in astutils 2019-07-13 16:13:21 +02:00
Daniel Marjamäki 316537a837 Avoid 'unsigned' for int variables 2019-07-13 16:06:24 +02:00
Daniel Marjamäki cff462c6ef Token deleteNext/deletePrevious parameters 2019-07-13 15:47:53 +02:00
Daniel Marjamäki bf9edc00c2 Fix compiler errors 2019-07-13 15:42:36 +02:00
Daniel Marjamäki f5e76a2d18 Avoid 'unsigned' when declaring int variables in checkuninitvar 2019-07-13 15:31:17 +02:00
Daniel Marjamäki 794d25fcf5 Avoid 'unsigned' when declaring int variables in Platform 2019-07-13 15:23:59 +02:00
IOBYTE 526a86dc60 Fix recursiveCount in CheckLeakAutoVar to really be recursive count. (#1988) 2019-07-13 07:40:24 +02:00
Scott Furry 61dcf10b6c Edit Change lib/errorlogger.h (#1992)
Shortening extremely long lines in file to improve readability.
2019-07-13 07:19:12 +02:00
Daniel Marjamäki 37d407641d Avoid 'unsigned' types. line number. 2019-07-13 06:27:40 +02:00
Daniel Marjamäki ae933c20c7 Fixed #1765 (Improve check: delete not handled well when there are extra parentheses) 2019-07-12 18:25:20 +02:00
Daniel Marjamäki 8ad3e43f92 Add handling of a simple C++ contract 2019-07-12 16:05:35 +02:00
Daniel Marjamäki 68cc7516a1 Annotations: Add annotation __cppcheck_in_range__(low,high) 2019-07-12 11:09:54 +02:00
IOBYTE 74e3114a64 Fix #9097 (Crash on thousands of "else ifs"s in gcc-avr package) (#1982)
* Fix #9097 (Crash on thousands of "else ifs"s in gcc-avr package)

* increase recursion count maximum to 512 because cppcheck was hitting the 256 limit

* 512 was too much for windows
2019-07-12 07:56:05 +02:00
Daniel Marjamäki 783f7f1648 Rename safeValues to unknownValues 2019-07-11 16:05:48 +02:00
IOBYTE 9700490e51 fix lib/checkclass.cpp:51:12: warning: enumeration value ‘eLambda’ not handled in switch [-Wswitch] (#1978) 2019-07-11 08:25:25 +02:00
Daniel Marjamäki a9d61c4ddd Fix Cppcheck warning 2019-07-10 22:08:27 +02:00
Daniel Marjamäki 5f217021ab Another attempt to fix appveyor 2019-07-10 21:30:50 +02:00
Daniel Marjamäki 45844ef962 Try to fix appveyor. Replace int64_t with MathLib::bigint. 2019-07-10 21:26:20 +02:00
Daniel Marjamäki 05d35b063d Function return: Extra check of safe function return values 2019-07-10 20:00:21 +02:00
Daniel Marjamäki c9906125de Safe functions: Check more possible function argument values 2019-07-10 16:59:05 +02:00
Daniel Marjamäki 9f548efbd3 Refactoring: enum class 2019-07-10 15:27:07 +02:00
Daniel Marjamäki 95d65c8c34 Refactoring; enum class 2019-07-10 14:05:16 +02:00
Rikard Falkeborn a1a14b8465 Fix FP with cast pointer to free() (#1961)
This fixes false positives when the pointer passed to free() (or similar
deallocation functions) is cast using a c-style cast.
2019-07-10 09:13:59 +02:00
Daniel Marjamäki 58076bc672 SymbolDatabase: Better handling of smart pointers 2019-07-09 17:32:19 +02:00
IOBYTE a05dfc9150 fix daca codeblocks crash (#1968)
* fix daca codeblocks crash

* fix the cause of the missing scope
2019-07-09 16:04:22 +02:00
Daniel Marjamäki 862c4ef87b Symboldatabase: Fix possible null pointer dereference if smart pointer type does not have a scope 2019-07-08 17:43:45 +02:00
Daniel Marjamäki a0b22410cf SymbolDatabase: Better handling of smart pointers 2019-07-07 21:52:49 +02:00
IOBYTE e551057f59 Refactor Tokenizer::simplifyUsing to use continue to reduce indentation (#1967)
* Refactor Tokenizer::simplifyUsing to use continue to reduce indentation

added function findTemplateDeclarationEnd to skip template declarations
to reduce duplicate code

* fix travis build
2019-07-07 18:33:33 +02:00
IOBYTE c902c5f688 Fix #9197 (Template name cache: Assertion `tok && tok->str() == ">"' failed.) (#1964) 2019-07-07 10:20:43 +02:00
Paul Fultz II b0d10273ed Fix issue 3695: Handle class pointers
This switches to use lifetime analysis to check for assigning to non-local variables:

```cpp
class test
{
public:

  void f()
  {
    int x;
    this->ptr = &x;
  }

protected:
  int *ptr;
};
```
2019-07-07 10:16:19 +02:00
IOBYTE 9569fa1374 Partial fix for #9191 (simplifyTypedef: Problem when namespace is used) (#1952)
* Partial fix for #9191 (simplifyTypedef: Problem when namespace is used)

This fixes simplifyUsing which has the same problem as simplifyTypedef.

simplifyUsing was designed to support using namespace but it was never
implemented. The changes are minor to add it.

simplifyTypedef requires much more work to support using namespace.

* reduce scope of variable

* make idx const
2019-07-06 20:22:13 +02:00
PKEuS ae86536128 Updated to Visual Studio 2019 2019-07-06 12:11:19 +02:00
Paul Fultz II 65af02f0cf Fix crash with lambda capture (#1960) 2019-07-06 10:46:17 +02:00
versat 57d44f1362 astyle formatting
[ci skip]
2019-07-05 14:00:59 +02:00
Rikard Falkeborn 839fcddd8a Fix #6115 (Add support to realloc to cfg files) (#1953)
* Allow to configure realloc like functions

* memleakonrealloc: Bring back tests.

The old memleak checker was removed, and the tests for it was removed in
commit 9765a2dfab. This also removed the
tests for memleakOnRealloc. Bring back those tests, somewhat modified
since the checker no longer checks for memory leaks.

* Add realloc to mem leak check

* Add tests of realloc buffer size

* Configure realloc functions

* Add test of freopen

* Allow to configure which element is realloc argument

* Fix wrong close in test

cppcheck now warns for this

* Update manual

* Update docs

* Rename alloc/dalloc/realloc functions

Naming the member function realloc caused problems on appveyor. Rename
the alloc and dealloc functions as well for consistency.

* Change comparisson order

* Remove variable and use function call directly

* Create temporary variable to simplify

* Throw mismatchError on mismatching allocation/reallocation

* Refactor to separate function

* Fix potential nullptr dereference

As pointed out by cppcheck.
2019-07-05 12:44:52 +02:00
Paul Fultz II e0ced1c415 Parse lambdas as functions (#1955)
* Parse lambdas as functions

* Fix issue with missing paren

* Fix error when parsing non-existent args

* Remove unused function variable
2019-07-05 12:30:42 +02:00
Rikard Falkeborn 2a17e624d9 Overlapping sprintf, improve handling of casts (#1945)
* Overlapping sprintf, improve handling of casts

If there is a cast of the argument buffer, cppcheck would print out the
expression including the cast, which looks a bit strange to talk about

    Variable (char*)buf is used as...

Instead, only print the variable name without the cast.

Also, handle arbitrary many casts (the previous code only handled one).
Multiple casts of the input arguments is probably an unusual case in
real code, but can perhaps occur if macros are used.

* Fix printing of variable

... and add a test.

* Simplify testcase
2019-07-05 12:27:39 +02:00
Paul Fultz II 5801fb26f0 Fix syntax error with lambda captures (#1954)
* Fix syntax error with lambda captures

* Fix issue when using initializer in lambdas
2019-07-05 12:26:01 +02:00
shaneasd 7e54f989f9 Update symbol database such that the override keyword implies that the function is also virtual (#1907)
* Update symbol database such that the override keyword implies that the function is also virtual

* Add test case for implicit override

* change isVirtual to hasVirtualSpecifier

* fix method documentation for getVirtualFunctionCalls and getFirstVirtualFunctionCallStack

* Fix isImplicitlyVirtual to consider the override keyword and document logic

* Fix getFirstVirtualFunctionCallStack and getVirtualFunctionCalls to use isImplicitlyVirtual instead of isVirtual so new test case passes
2019-07-04 12:32:32 +02:00
Rikard Falkeborn 60a213e6a5 Fix #9047 (c-style casts before malloc) (#1930)
* Fix #9047 (c-style casts before malloc)

Note that there are still no warnings for c++-style casts

* Fix memleak check with casts of assignments in if-statements

* Fix possible null pointer dereference

As pointed out by cppcheck.

* Add check of astOperand2 when removing casts

This is similar to how it is done in other checks.
2019-07-03 08:39:44 +02:00
IOBYTE c4933acb5a Fixed #9147(SymbolDatabase bailout: unhandled code) (#1948)
* Fixed #9147(SymbolDatabase bailout: unhandled code)

* add test for #9183
2019-07-03 08:35:48 +02:00
Daniel Marjamäki f84dcc4738 astyle formatting
[ci skip]
2019-07-03 08:29:47 +02:00
Paul Fultz II 8f4cb36e1e Check for more garbage code (#1949)
* Check for garbage commas

* Find garbage dot operator
2019-07-03 08:28:24 +02:00
Ken-Patrick d6f6e68fa2 Fix false positive 9167 (#1904)
Skip returns from local class/struct definition in FwdAnalysis.
2019-07-03 08:17:06 +02:00
PKEuS d74f8c678f Set version to 1.88.99/1.89 dev 2019-07-02 20:59:52 +02:00
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 e459762bcd Suppress Code semantic and syntax warnings (#1936)
Sources were built with Clang but with increased verbosity of error detection.

A number of syntax and semantic warnings were encountered. Commit adds
changes to correct these warnings.

Some changes involve removing extra, and unncessary, semi-colons at EOL
(e.g. at end of switch clause).

Project astyle settings are not currently setup to detect if a file is to
have an extra carriage return after the last line of data. Two files were
altered to ensure an extra carriage return.

An advisory to enhance code was encountered in triage code. Clang advisory
on a for-loop interation value suggested that:
`use reference type 'const QString &' to prevent copying`
2019-06-30 21:43:25 +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 4d81b77249 Fixed Cppcheck warning, condition is always false 2019-06-30 18:43:55 +02:00
Daniel Marjamäki 56df6169fb Fixed #8356 (ValueFlow: variable is not changed in for loop) 2019-06-30 17:50:35 +02:00
albert-github 280a0a7b2f Wrong argument name used in documentation (#1937)
Trivial error in documentation
2019-06-30 15:41:53 +02:00
Scott Furry 1994b21ae5 Minor Corrections to Doxygen data (#1935)
Increasing the verbosity in Clang, warnings were produced that identified
differences in code and doxygen-formatted comments.

Corrections applied to silence warnings yet still convey intent of original comments.
2019-06-30 09:17:42 +02:00
Daniel Marjamäki d9a9743b8a Revert "Calculate token scopes in advance rather than as the tokenlist is iterated (#1882)"
This reverts commit 0d7836f3a0.
2019-06-30 09:12:18 +02:00
rebnridgway 0d7836f3a0 Calculate token scopes in advance rather than as the tokenlist is iterated (#1882)
* Added scopeinfo member to token class

Moved ScopeInfo2 declaration here as well because that's where it needs to be now.

* Added scopeinfo accessors and declaration to class

* Add new method for calculating scopes

This replaces the methods in the TemplateSimplifier which calculate the current scope as the token list is iterated.  The old method required checking if the scope had changed for every token multiple times (for multiple iterations), which was surprisingly costly.  Calculating scopes in advance like this decreases runtime on a worst-case file by around thirty percent.
ScopeInfo objects are disposed of when the TemplateSimplification is done as they are not used later.

* Add calculateScopes method to header

* Removed code that calculated current scope

This has been replaced by code that calculates the scopes up front and stores them with each token, which is much faster.

* Fixed compile errors from extra parentheses

* Added missing code to fix memory leak

* Added code to actually clean up ScopeInfo structs

* Tidy up a dodgy for loop

* Convert argument to const ref

* Calculate missing scopes

As the templatesimplificator expands templates and does multiple passes it needs to make sure all scopes are calculated.

* Remove copying the scope to the next token

This is now done properly when scopes are calculated.

* Remove call to calculateScopes

This is now done by the TemplateSimplifier.

* Recalculate scopes for every pass of simplifyTemplates

* Add code to calculate extra scopes as they are added

I thought that this might be useful for calculating scopes when Tokens are created, but as there are several ways of creating Tokens that don't guarantee that they are placed in a list it is easier to just calculate scopes when you know you have a list and when you know you're adding to a list.

* Fix several bugs and poorly designed code

Remove the global scopes collection, and clean them up instead by iterating through the tokenlist to find them.  This means scopes can be calculated by functions in the Token class as well as in the Tokenizer class without leaking the scope object.
Fix a couple of bugs in the calculateScopes method and make it more efficient.

* Remove unnecessary calls to calculateScopes

* Move brace to correct position

Calculating scopes during insertToken only needs to happen if we created a new Token.

* Handle 'using namespace' declarations separately

This fixes a bug caused by a statement matching 'struct B < 0 > ;'

* Fix argument name mismatch

* Actually use newScopeInfo when inserting Token

* Switch to using shared_ptr to hold scopeInfos

This means ScopeInfo2 objects get properly cleaned up when they are no longer needed.

* Change ScopeInfo member to be a shared_ptr

* Update code to use shared_ptr

* Add missing include for shared_ptr

* Remove unnecessary cleanup code

This has been replaced by shared_ptr for ScopeInfo2 objects
2019-06-29 14:34:22 +02:00
Rikard Falkeborn d1d622b74c Valueflow: support global static const variables (#1861) 2019-06-29 14:33:55 +02:00
Daniel Marjamäki faaabc74a7 Set version 1.88 2019-06-29 08:38:13 +02:00
Daniel Marjamäki 341406ab17 Fixed Cppcheck warning; ::AddonInfo::getFullPath can be static 2019-06-29 07:59:55 +02:00
Daniel Marjamäki 0a41f1ad6b Fix Cppcheck warning: Suppressions::dump can be const 2019-06-29 07:53:32 +02:00
Daniel Marjamäki 84cc09d17c Update Copyright 2019-06-29 07:49:14 +02:00
Daniel Marjamäki 9c3c2d785b Fixed Cppcheck warning 2019-06-29 07:46:25 +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
Carlo Marcelo Arenas Belón ec4e43767e minor improvements (#1929)
* lib: isNonBoolStdType no longer needed

lib/checkbool.cpp:50:13: warning: unused function 'isNonBoolStdType'
      [-Wunused-function]
static bool isNonBoolStdType(const Variable* var)

* cmake: C++11 is required

also change instructions to a more common syntax
2019-06-28 06:57:05 +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
Daniel Marjamäki c97dc79815 --addon: Use json for addon output 2019-06-24 19:29:43 +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
IOBYTE 46b543ba27 template simplifier: stop running passes when nothing was simplified. (#1914) 2019-06-23 10:55:09 +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 beea7fa8d2 Token::index(): Created Token member that indicates the Token position in the token list. It can be used to quickly check if tok1 precedes tok2. 2019-06-21 22:16:23 +02:00
Daniel Marjamäki d636a83f8b Tokenizer: Assign Token 'progressValue' before returning so they are set properly when the checks are run 2019-06-21 08:43:19 +02:00
Daniel Marjamäki c98ceb6e14 Tweak bailout so it's only used in unused template classes 2019-06-20 14:00:44 +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
Daniel Marjamäki 59c7be307c Travis: Fix test/cli testing 2019-06-16 19:11:12 +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
Daniel Marjamäki ba0a75881a Refactor AddonInfo::getAddonInfo 2019-06-16 15:46:20 +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 61a259597b Fix Cppcheck warnings 2019-06-15 13:28:01 +02:00
Daniel Marjamäki 8359d85b12 Fix Cppcheck warning 2019-06-15 13:23:21 +02:00
Daniel Marjamäki 46cad95238 Fix Cppcheck warnings 2019-06-15 13:05:17 +02:00
Daniel Marjamäki d1f80a2a91 Fix Cppcheck warnings 2019-06-15 13:01:45 +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
Daniel Marjamäki e37b92fb3b astyle formatting
[ci skip]
2019-06-14 12:07:22 +02:00
eivindt 44670005ea Record C/CPP/Posix Standard used for cppcheck in dump file / use this for misra checking (#1782)
* Add cmd parameter for choosing between C90 and C99

Misra specifies different requirements to the uniqueness of
macros/enums/variables depending on what C standard
that's being used.

* Add standards configuration to each dump file

Read standards config from misra addon to decide what rules to use.

* Posix as standard setting should be deprecated.  Don't include this in the xml

* Rewritten to use a switch
2019-06-14 12:06:57 +02:00
eivindt 5dd7dacfd7 Fix small error using correct name for addon script when specified in json file (#1881) 2019-06-13 14:11:21 +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 81e41f129a template simplifier: improve populating template specialization maps (#1873)
Declaration to specialization mapping is still not perfect.
2019-06-07 08:22:34 +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
orbitcowboy 821903e2e1 Running astyle [ci skip] 2019-06-02 13:29:20 +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
orbitcowboy 79ab9cf84d Running astyle [ci skip]. 2019-05-31 10:14:52 +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 f66cbac0a4 Fix Cppcheck warning 2019-05-30 21:48:12 +02:00
Daniel Marjamäki de07e2177c Fix Travis hang 2019-05-30 21:25:14 +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
orbitcowboy 66e8ec90de wxwidgets.cfg: Added support for wxWindow::ClientToScreen(). 2019-05-28 08:50:38 +02:00
orbitcowboy f54c60c13d Running astyle [ci skip] 2019-05-28 08:49:59 +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 b3c3ecf926 MathLib: Removed condition that is evaluates always to 'false'. 2019-05-26 10:46:12 +02:00
Paul Fultz II eb1c9ba357 Cache template name position to improve performance
This improves the performance of the templatesimplefier by caching the template name position. I am not sure if the works entirely correctly but all the tests do pass with this change. Running this with gtest headers without removing unused template headers the time went from 48s to 5s, almost a 10x improvement.
2019-05-25 10:08:51 +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 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
Carlo Marcelo Arenas Belón bf5c71bdca sync (#1835)
* build: remove -Wabi and add -Wundef

gcc >= 8 throws a warning about -Wabi (without a specific ABI version)
being ignored, while -Wundef seems more useful (as shown by the change
in config.h, which was probably an unfortunate typo)

travis.yaml should probably be updated soon, but was left out from this
change as the current images don't yet need it

* lib: unused function in valueflow

refactored out since 8c03be3212

lib/valueflow.cpp:3124:21: warning: unused function 'endTemplateArgument' [-Wunused-function]

* readme: include picojson

* make: also clean exe
2019-05-17 09:31:41 +02:00
Daniel Marjamäki 57c6628732 Revert 'Cleaning up unsimplified templates'. This fix caused problems. 2019-05-16 21:11:04 +02:00
Daniel Marjamäki 34cf62452e Change approach for Tokenizer::createLinks2: assume that <> should be linked 2019-05-16 20:50:56 +02:00
Daniel Marjamäki 0144db2490 Fixed 'Syntax Error' when < link is not set properly 2019-05-15 21:34:56 +02:00