Commit Graph

10607 Commits

Author SHA1 Message Date
Daniel Marjamäki f40a80c349 Use 'normal' checking instead of 'simplified' 2019-03-16 07:19:48 +01:00
Daniel Marjamäki a2a216bbe3 SymbolDatabase: Improved handling of 'normal' non simplified token list 2019-03-15 19:00:42 +01:00
Daniel Marjamäki 92485245ce Restore severity for 'autoVariables' 2019-03-15 15:13:11 +01:00
Sebastian 08d41ab8af
Load std.cfg before all other libraries (#1740)
- CLI: Save the libraries that should be loaded to a list and load them
after the std.cfg has been loaded.
- GUI: Load std.cfg (and windows.cfg / posix.cfg when applicable) before
setting other options and loading the other libraries.
In the project-file-dialog the std.cfg is searched first. If some
other library fails to load is is retried with first loading std.cfg.
- boost.cfg: Enable containers that depend on std containers.
2019-03-15 06:59:37 +01:00
Paul Fultz II 3615eac347 Move useStlAlgorithm to normal checking (#1741) 2019-03-15 06:15:56 +01:00
Daniel Marjamäki a1ade2dd7d Refactoring: Use range for 2019-03-14 19:57:58 +01:00
Daniel Marjamäki 56c47fc6ed Refactoring: use continue 2019-03-14 19:53:45 +01:00
Daniel Marjamäki 3656f1ae4f Auto variables: Fix false negatives for normal tokens 2019-03-14 13:51:35 +01:00
Daniel Marjamäki 6eeee743d2 Auto variables: Minor cleanup 2019-03-14 06:41:11 +01:00
Daniel Marjamäki b984897526 ValueFlow: Fix sizeof for array of library type 2019-03-13 18:31:41 +01:00
Daniel Marjamäki 2ecfae0a98 CheckBufferOverrun: the bufferNotZeroTerminated did not work well, hide that for now 2019-03-13 06:45:01 +01:00
Daniel Marjamäki 81a1d744c6 CheckBufferOverrun: fix FP for array definition of static class member 2019-03-13 06:39:09 +01:00
Daniel Marjamäki 67e8b99c2c CheckBufferOverrun: Readd a check for strncpy/memcpy/etc 2019-03-12 21:15:26 +01:00
Daniel Marjamäki 2a00667609 CheckBufferOverrun: cleanup 2019-03-12 18:58:14 +01:00
Daniel Marjamäki 11e32ff445 ValueFlow: Handle compound assignments in execute() 2019-03-12 18:53:58 +01:00
Daniel Marjamäki 0c08f6db6c CheckBufferOverrun: Use AST to lookup array 2019-03-12 06:46:38 +01:00
Daniel Marjamäki 4ababeb704 Fix 'make checkcfg' 2019-03-11 21:39:39 +01:00
Daniel Marjamäki ea23033a65 Array index out of bounds: Fix false positive 2019-03-11 20:33:08 +01:00
Daniel Marjamäki 7b17b33a49 ValueFlow: fix handling of sizeof(*p) 2019-03-11 20:32:24 +01:00
Daniel Marjamäki 17253cdb55 buffer overflow: Fix false positive 2019-03-11 19:40:17 +01:00
Daniel Marjamäki bd048085bd Add CheckBufferOverrun::arrayIndexThenCheck 2019-03-11 19:20:06 +01:00
Daniel Marjamäki a933261e14 Add message id arrayIndexOutOfBoundsCond 2019-03-11 19:12:03 +01:00
orbitcowboy 0721c9f7f0 Running astyle [ci skip]. 2019-03-11 15:32:30 +01:00
Daniel Marjamäki 729f57d8f1 Start a major rewrite of CheckBufferOverrun. For now only the 'array index' and 'buffer overflow' checks are rewritten.
There are important TODOs still; for instance adding CTU support using our CTU infrastructure, add handling of pointers (maybe I'll use FwdAnalysis for this), add handling of multidimensional arrays, etc..
2019-03-11 12:34:33 +01:00
Daniel Marjamäki 34711bcb93 Remove unused functions 2019-03-11 12:23:22 +01:00
Daniel Marjamäki df8cfe2fc6 Travis: Fix Cppcheck warning 2019-03-10 12:24:41 +01:00
Rikard Falkeborn 6a3dd9a185 Handle concatenated string and char literals
This handles concatenated strings and characters from simplecpp.
Previously, L'c' would be preprocessed to the tokens  "L" and "'c'".
cppcheck would then remove the "L" token and set "'c'" to be a wide
character literal. Now, it needs to remove the prefix instead.

When doing this, add handling of utf32 encoded literals (U) and UTF-8
encoded literals (u8).
2019-03-10 10:38:50 +01:00
Daniel Marjamäki 3eb5de756c Buffer overrun: Refactorings; use range for loops and write in message 2019-03-09 22:19:09 +01:00
Daniel Marjamäki 4ce6de39c5 CheckCondition: Moved checks to 'normal' 2019-03-09 22:00:59 +01:00
Daniel Marjamäki ea9b2032c1 CheckClass: Moved checks to 'normal' 2019-03-09 21:38:36 +01:00
Daniel Marjamäki 69c05acd3b CheckBoost: Use 'normal' checking 2019-03-09 20:00:31 +01:00
Daniel Marjamäki 5a42c54d0f CheckBool: Use normal checking 2019-03-09 19:16:07 +01:00
Daniel Marjamäki ac42382cd9 Rewrite CheckBool::checkAssignBoolToPointer to use ValueType 2019-03-09 19:15:06 +01:00
Daniel Marjamäki e17ddfd964 Changed AST for variable declarations with initializations 2019-03-09 19:09:15 +01:00
Daniel Marjamäki 1b4895a579 ValueType: Set ValueType for false/true 2019-03-09 17:27:27 +01:00
Daniel Marjamäki 5a32d2d017 Moved CheckAutoVariables::autoVariables to normal checking 2019-03-09 16:53:43 +01:00
Daniel Marjamäki 38d5712aaa Moved CheckAssert::assertWithSideEffects to normal checking 2019-03-09 16:50:50 +01:00
Daniel Marjamäki b9ac77a31b Uninitialized variables: Fixed false positive 2019-03-09 11:30:45 +01:00
Daniel Marjamäki f36ca56e7d Moved CheckStl::redundantCondition to normal checking 2019-03-09 07:53:49 +01:00
Daniel Marjamäki f9fe6cc96a STL: Removed auto_ptr checking. 2019-03-09 07:48:01 +01:00
Daniel Marjamäki d7a645dcc3 Moved CheckStl::uselessCalls to normal checking 2019-03-09 07:37:08 +01:00
Rikard Falkeborn a53b016414 checknullpointer: Remove duplicated include (#1732) 2019-03-08 20:55:09 +01:00
Daniel Marjamäki 45a0c2ebf5 Revert "Moved CheckStl::checkAutoPointer to normal checking"
This reverts commit 6dc9727ffd.
2019-03-08 20:53:37 +01:00
Daniel Marjamäki 6dc9727ffd Moved CheckStl::checkAutoPointer to normal checking 2019-03-08 20:41:28 +01:00
Daniel Marjamäki 95a20c0233 Moved CheckStl::string_c_str to normal checking 2019-03-08 20:39:43 +01:00
Daniel Marjamäki fdf1d6fdee Moved CheckStl::erase to normal checking 2019-03-08 20:36:40 +01:00
Daniel Marjamäki fdfe39299c Moved CheckStl::pushback to normal checking 2019-03-08 20:33:16 +01:00
Daniel Marjamäki 5fe48f3cd2 Moved CheckStl::mismatchingContainers to normal checking 2019-03-08 20:31:00 +01:00
Daniel Marjamäki b91bb2e523 Moved CheckStl::iterators to normal checking 2019-03-08 20:28:28 +01:00
Daniel Marjamäki 8f2d70e61d Move CheckStl::if_find to normal checking 2019-03-08 20:23:37 +01:00
Daniel Marjamäki 725abbfac3 Move CheckStl::missingComparison to normal checks 2019-03-08 20:19:40 +01:00
Daniel Marjamäki 75ce67f4b8 Fixed #9027 (cppcheck on Centos 7 - segmentation fault below CheckCondition::multiCondition2) 2019-03-08 19:27:20 +01:00
Sebastian c8003d47e2
checkuninitvar.cpp: Use argument direction "out" info from library cfg (#1730)
CheckUninitVar::isMemberVariableAssignment uses argument direction "out"
now also to check for assignment when the member variable is handed over
to a function by reference.
testuninitvar.cpp: Improve tests, use a test library configuration.
2019-03-08 18:42:24 +01:00
amai2012 eb9edbc177 #9024 Crash caused by package "procserv" in lib/token.h:921 function Token::getKnownIntValue - Fix and test for alternative code example. 2019-03-08 11:07:33 +01:00
Daniel Marjamäki 6eaf2c03d9 CheckOther::checkInvalidFree: Move check to normal checking. And clarify the message. 2019-03-07 06:35:44 +01:00
Daniel Marjamäki 17e73fd144 Move CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse to Normal checking 2019-03-06 21:27:19 +01:00
Daniel Marjamäki f20936ed8a Moved CheckOther::checkPassByReference to normal checking 2019-03-06 20:59:45 +01:00
Daniel Marjamäki 9d5f672dbc Unused struct member: Fix FPs seen in daca@home results for template structs 2019-03-06 20:51:48 +01:00
Daniel Marjamäki 572d7eb86c Moved CheckOther::clarifyCalculation to normal checking 2019-03-06 20:43:28 +01:00
Daniel Marjamäki ee9053f219 Moved CheckOther::checkRedundantCopy() to normal checking 2019-03-06 20:38:13 +01:00
Sebastian 6228ea2266
checkuninitvar.cpp: Use argument direction info from library config. (#1728)
CheckUninitVar::isMemberVariableAssignment uses argument direction
to check for assignment when the member variable is handed over to a
function by reference. Currently implemented for "in" direction. "out"
will be added with another commit.
2019-03-06 19:26:38 +01:00
Daniel Marjamäki ad37664e86 Changed severities 2019-03-06 19:00:58 +01:00
Daniel Marjamäki c32d015337 Fixed false positives from terminateStrncpy 2019-03-06 18:50:50 +01:00
Daniel Marjamäki 3f37d5ac2d Refactoring strncpy/strncat checking to use ValueFlow and AST 2019-03-06 09:04:04 +01:00
Daniel Marjamäki 37814513f8 Revert "Moved all simplified CheckOther checks from simplified to normal checking"
This reverts commit 2900690881.
2019-03-06 07:08:56 +01:00
Daniel Marjamäki 2900690881 Moved all simplified CheckOther checks from simplified to normal checking 2019-03-06 06:33:51 +01:00
Daniel Marjamäki 06c2019676 Moved CheckOther::checkPipeParameterSize from simplified to normal checking 2019-03-06 06:28:13 +01:00
Carlo Marcelo Arenas Belón cb973cbb7b lib: reorders settings to match definition (-Wreorder) (#1727)
lib/settings.cpp:53:7: warning: field 'removeUnusedIncludedTemplates' will be
      initialized after field 'removeUnusedTemplates' [-Wreorder]
      removeUnusedIncludedTemplates(false),
      ^
lib/settings.cpp:54:7: warning: field 'removeUnusedTemplates' will be
      initialized after field 'checkConfiguration' [-Wreorder]
      removeUnusedTemplates(false),
      ^
2019-03-06 06:12:02 +01:00
Daniel Marjamäki fda0f52424 Add --remove-unused-templates flag to remove all unused templates 2019-03-05 14:58:02 +01:00
IOBYTE 5ee6c2138c Fixed #9016 (tokenizer: wrong simplification for operator ^ (){}) (#1724) 2019-03-05 11:35:45 +01:00
Sebastian 0934577dda
Library configuration: function argument direction fixes and enhancements (#1722)
* std.cfg: Add further argument directions (in, out, inout).

* testlibrary.cpp: Add test for function argument direction configuration.

* std.cfg: runastyle and add some more direction configurations.

* library.h: Add documentation for function argument direction enum.

* Do not use "direction" library information for pointer arguments.

Also fix further unmatched uninitvar messages in std configuration
tests.

* std.cfg: Add more argument direction configurations.

* test/cfg/std.c: Add test for argument direction configuration.

* astutils.cpp: Only ignore pointer arguments for out/inout arguments.

* library.h: Use suggested documentation for argument direction enum.
2019-03-04 22:57:40 +01:00
Daniel Marjamäki 3675318208 Added --remove-unused-included-templates option 2019-03-04 19:10:49 +01:00
Daniel Marjamäki c5a512338e --check-headers=no: remove more templates in headers that are not used in the source file 2019-03-03 20:18:54 +01:00
IOBYTE 40d7d5a3d0 template simplifier: fix return type of out of line member function when it is a template parameter (#1723) 2019-03-03 19:42:46 +01:00
Daniel Marjamäki 41db8afe87 --check-headers=no: remove templates in headers that are not used in the source file 2019-03-03 12:56:37 +01:00
Daniel Marjamäki eb109af00f Replace Token::simpleMatch with Token::Match for complex pattern 2019-03-03 12:40:55 +01:00
Daniel Marjamäki 59ec5f961f --check-headers=no: remove types in headers that are not used in the source file 2019-03-03 12:36:33 +01:00
Daniel Marjamäki 411a3f09f7 --check-headers=no: Remove unused function declarations 2019-03-03 09:18:12 +01:00
IOBYTE b222953bae template simplifier: only constant fold template instantiation arguments (#1721)
* template simplifier: only constant fold template instantiation arguments

* Fix travis build.
2019-03-03 07:40:55 +01:00
Daniel Marjamäki f5c274b3b1 Added '--check-headers=no' option. 2019-03-02 19:52:15 +01:00
Daniel Marjamäki 8a3b73ffdb Do not write extra uninitvar warnings 2019-03-02 13:17:15 +01:00
Sebastian 9a5fcddb5d
Library configuration: Enable configuring the direction of arguments. (#1717)
This enhances the library configuration so the direction of function
arguments can be specified (in, out, inout).
isVariableChangedByFunctionCall() uses this information now to avoid
guessing.
2019-03-01 15:47:08 +01:00
Daniel Marjamäki 845c407ab7 Fixed pattern matching in isVariableChanged() to handle normal token list better 2019-03-01 13:23:03 +01:00
IOBYTE b78b3c6ab1 Fixed #9005 (Syntax error on valid C++) (#1716) 2019-03-01 08:18:53 +01:00
PKEuS 8af3708aa3 Optimization: Library does not need to store "#define " substring for each define 2019-02-28 22:34:26 +01:00
Daniel Marjamäki 5563fef7bb Fixed #9008 (new crash in clang test suite) 2019-02-28 20:34:07 +01:00
Daniel Marjamäki 4f5a426fe5 Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference 2019-02-28 17:02:46 +01:00
Daniel Marjamäki 494dd2ba3a Revert "Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference"
This reverts commit 14a0031e88.
2019-02-28 15:56:25 +01:00
Daniel Marjamäki 14a0031e88 Improved isVariableChangedByFunctionCall, better logic when parameter might be passed by reference 2019-02-28 10:26:47 +01:00
Daniel Marjamäki 857681a049 Make quick fix for uninitialized variable false positive. Will look more at this soon. 2019-02-28 09:52:52 +01:00
IOBYTE 98bf112352 template simplifier: fix recursive variable templates (#1711) 2019-02-28 08:30:04 +01:00
Sebastian c8a7a4c653
library.cpp: WarnInfo: Fix crash (#1697)
If no 'alternatives' argument was specified and the `<warn/>` element
did not contain any text Cppcheck crashed because of a null pointer
access.
If there is no 'reason' and no 'alternatives argument and also no text loadFunction() returns with an error.
2019-02-28 06:19:42 +01:00
PKEuS 11daabc1a8 Set version to 1.87.99/1.88 dev 2019-02-27 21:30:54 +01:00
Daniel Marjamäki e27a7a585f Fix uninitvar false positive when taking address of variable 2019-02-27 18:44:30 +01:00
Daniel Marjamäki 80143725dd Fixed #8999 (False positive uninitvar related to casting) 2019-02-27 17:58:25 +01:00
Daniel Marjamäki 226f0c7544 Fixed ValueType for auto variable 2019-02-27 10:28:18 +01:00
Paul Fultz II 032020c40d Fix issue 9001: FP: Found suspicious operator ',' [constStatement] 2019-02-27 07:09:22 +01:00
Paul Fultz II e846312fed Check subtraction of pointers to different objects 2019-02-27 06:55:48 +01:00
rikardfalkeborn 0e988cc755 Fix #8992: Add originalTypeToken to auto (#1701) 2019-02-27 06:44:31 +01:00
rikardfalkeborn c9efc26578 valueflow: Mark getLifetimeToken() static (#1703)
Fixes a compiler warning about missing declaration.
2019-02-26 23:35:11 +01:00
Daniel Marjamäki c44e2ed378 sizeof: write inconclusive warning if calculation in sizeof is done indirectly by macro 2019-02-26 21:06:44 +01:00
Daniel Marjamäki 9e93e89a4d UninitVar: Fix false positives when there is possible cast 2019-02-26 19:26:46 +01:00
IOBYTE bf85767829 template simplifier: make sure all instantiations are found and expan… (#1696)
* template simplifier: make sure all instantiations are found and expanded in #5097

* template simplifier: check output on another test

* template simplifier: add output to another test
2019-02-26 06:41:04 +01:00
IOBYTE 3f257d6310 template simplifier: instantiate template class when something inside… (#1695)
* template simplifier: instantiate template class when something inside class instantiated.

* template simplifier: add output to another test that now works
2019-02-25 21:01:34 +01:00
Daniel Marjamäki ef6fc67da4 Move CheckString::checkAlwaysTrueOrFalseStringCompare() from runSimplifiedChecks() to runChecks() 2019-02-25 18:11:33 +01:00
Daniel Marjamäki f1146e398a Moved CheckString::sprintfOverlappingData from runSimplifiedChecks to runChecks 2019-02-25 09:23:03 +01:00
Daniel Marjamäki 4218698fb1 Moved CheckString::checkIncorrectStringCompare from runSimplifiedChecks to runChecks 2019-02-25 09:08:16 +01:00
Daniel Marjamäki d84d8885f7 SymbolDatabase: Fix TODO assertions 2019-02-24 19:11:18 +01:00
Daniel Marjamäki ef731064bd Fixed #8964 (ValueType: auto constness) 2019-02-24 08:16:08 +01:00
Daniel Marjamäki c855cf8682 ValueType: Better constness for auto variable 2019-02-23 18:16:18 +01:00
Daniel Marjamäki b43572d75e Fixed #8969 (C++ functional cast not handled correctly) 2019-02-23 17:29:53 +01:00
Daniel Marjamäki 68062e3702 Fixed #8954 (false positive: Local variable x shadows outer variable) 2019-02-23 16:22:22 +01:00
Paul Fultz II fd3c1fd040 Fix issue 1777: Undefined Behavior: Comparing pointers to different objects
This uses the lifetime analysis to check when comparing pointer that point to different objects:

```cpp
int main(void)
{
    int foo[10];
    int bar[10];
    int diff;

    if(foo > bar)   // Undefined Behavior
    {
       diff = 1;
    }

    return 0;
}
```
2019-02-23 08:32:08 +01:00
ivangalkin 1b703ce58e 7772 Add uninitMemberVarPrivate to errorlist (really) #1557 (#1686)
Previous attempt 70527a78f7
doesn't work because equal error messages are filtered.
2019-02-23 08:07:46 +01:00
Paul Fultz II 941dd79f0d Fix FP issue 8986: constArgument check warns for elements of const array (#1683) 2019-02-22 06:39:59 +01:00
Paul Fultz II 507c7a4388 Improvement to lifetime tracking of addressof and derefencing
This will now warn for cases like this:

```cpp
auto& f() {
    std::vector<int> x;
    return x[0];
}
```

It also improves the handling of address of operator, so it can now warn across some function calls, like this:

```cpp
int& f(int& a) {
    return a;
}
int* hello() {
    int x = 0;
    return &f(x);
}
```
2019-02-22 06:38:56 +01:00
Paul Fultz II 715714f4de Forward lifetimes in "for" loops (#1682)
* Forward lifetimes in for loops

* Format
2019-02-22 06:37:02 +01:00
Paul Fultz II 0ee3f678b5 Fix issue 8987: False positive knownConditionTrueFalse (#1678) 2019-02-20 15:28:31 +01:00
Paul Fultz II dfaf75db54 Fix issue 8984: FP constStatement regression with qualified name (#1676) 2019-02-19 07:08:36 +01:00
Kamil Dudka 2908593cf6 checkautovariables: eliminate false positives on assignment of &ptr->item (#1667)
Even if `ptr` is a local variable, the object `ptr->item` might be not.
So taking address of `ptr->item` is definitely not unsafe in general.

This commit fixes false positives triggered by commit
1.85-249-gf42648fe2 on the following code of sssd:

https://github.com/SSSD/sssd/blob/d409df33/src/sbus/request/sbus_request.c#L359
2019-02-18 09:35:07 +01:00
Paul Fultz II cf1ad5087a Extend constStatement checker
This reworks constStatement to find more issues. It catches issue [8827](https://trac.cppcheck.net/ticket/8827):

```cpp
extern void foo(int,const char*,int);
void f(int value)
{
        foo(42,"test",42),(value&42);
}
```

It also catches from issue [8451](https://trac.cppcheck.net/ticket/8451):

```cpp
void f1(int x) {
    1;
    (1);
    (char)1;
    ((char)1);
    !x;
    (!x);
    ~x;
}
```

And also:

```cpp
void f(int x) {
    x;
}
```

The other examples are not caught due to incomplete AST.
2019-02-15 13:31:40 +01:00
rikardfalkeborn dc4e7cef88 Run simplifyPlatformTypes on library return types (#1672)
Add a call to simplifyPlatformTypes() in
SymbolDatabase::setValueTypeInTokenList() to simplify return types of
library configured functions. This fixes the FN in #8141. Regression
tests are added, both for the original issue and another FN in the comments.

In order to do that, move simplifyPlatformTypes() to TokenList from Tokenizer.
This is a pure refactoring and does not change any behaviour. The code was
literally copy-pasted from one file to another and in two places
'list.front()' was changed to 'front()'.

When adding the call to simplifyPlatformTypes(), the original type of
v.size() where v is a container is changed from 'size_t' to 'std::size_t'.
Tests are updated accordingly. It can be noted that if v is declared as
'class fred : public std::vector<int> {} v', the original type of 'v.size()'
is still 'size_t' and not 'std::size_t'.
2019-02-15 13:29:52 +01:00
IOBYTE 8bd5b3eccf Fixed #8962 ("(debug) Unknown type 'T'" with template typename parame… (#1671)
* Fixed #8962 ("(debug) Unknown type 'T'" with template typename parameter)

Only simple one parameter template functions with one function parameter
are supported.

* Added TODO test case for FIXME.
2019-02-14 11:48:59 +01:00
IOBYTE 9dc5dbe1ab Fixed #8976 (Crash on `using mystring = std::string;`) (#1663)
* Fixed #8976 (Crash on `using mystring = std::string;`)

* templateSimplifier: move test case to correct file.
2019-02-12 09:39:01 +01:00
Carlo Marcelo Arenas Belón 03c9477028 settings: -Wreorder fix (#1664)
otherwise showing (with Apple LLVM version 10.0.0):

  lib/settings.cpp:34:7: warning: field 'jointSuppressionReport' will be
      initialized after field 'maxCtuDepth' [-Wreorder]
      jointSuppressionReport(false),
2019-02-12 09:07:59 +01:00
IOBYTE 9490d0db8c token simplifier: fix crashes related to #8972 (#1659) 2019-02-11 07:45:03 +01:00
Daniel Marjamäki 10b4215839 UninitVar: use normal token list instead of simplified token list 2019-02-11 07:43:16 +01:00
Daniel Marjamäki 6ca1aba4a7 UninitVar: Fix --experimental-fast issues 2019-02-10 19:00:01 +01:00
Simon Martin eaaff30e65 Ticket #8878: Properly simplify typedefs within template instantiations. (#1656) 2019-02-10 09:45:33 +01:00
Daniel Marjamäki 4f232e41dd Add --experimental-fast option 2019-02-09 14:40:50 +01:00
Daniel Marjamäki 502d5e9142 1.87: Set versions 2019-02-09 09:07:27 +01:00
Daniel Marjamäki 9337af8965 astyle formatting 2019-02-09 08:48:10 +01:00
Paul Fultz II 797eccc203 Fix possible out of bounds access on arguments (#1652)
* Fix possible outbounds access on arguments

* Log a warning when the arguments mismatch

* Format
2019-02-09 08:47:36 +01:00
IOBYTE 155e4ce912 Fixed #8971 ("(debug) Unknown type 'x'." using alias in class members) (#1653)
* Fixed #8971 ("(debug) Unknown type 'x'." using alias in class members)

* template simplifier: partial fix for #8972

Add support for multi-token default template parameters.

* template simplifier: fix for #8971

Remove typename outside of templates.
2019-02-09 08:34:59 +01:00
Daniel Marjamäki bd7790fd8c Update copyright year 2019-02-09 07:24:06 +01:00
Paul Fultz II d7c20b15e7 Fix FP with const argument when doing a variable and cast (#1649) 2019-02-07 14:59:09 +01:00
IOBYTE 7025254c26 Fixed #8969 (syntax error: template) (#1647)
Fixed template detection to handle multi-token template parameters.
2019-02-07 08:50:49 +01:00
Daniel Marjamäki 14a312e310 useInitializationList: Skip warning when rhs is a multi line lambda. For readability it might be better to have assignments in constructor in this case. 2019-02-05 19:53:10 +01:00
IOBYTE 1faae52d06 Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias) (#1643)
* Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias)

This commit adds non-template type alias support to the template
simplifier.  Only relatively simple type aliases are supported at this
time. More complex types will be added later.

--debug-warnings will show unsupported type aliases.

Type alias support will be removed from the symbol database in the
future.  Type alias tests have been removed from the symbol database
tests.

* Add the changes.

* Fix codacy warning.

* Fix travis warnings.
2019-02-05 08:52:23 +01:00
Daniel Marjamäki b7631b0390 Add more timers in tokenizer 2019-02-04 21:13:59 +01:00
Daniel Marjamäki 23599428cb Clarify Cppcheck output 2019-02-03 19:49:27 +01:00
Daniel Marjamäki 437800f46d CLI: Added --max-ctu-depth 2019-02-03 17:51:36 +01:00
Daniel Marjamäki a4406aca32 Fixed #7845 (Leak reported when ignoring return value of 'new', even if pointer saved by constructor) 2019-02-03 12:15:05 +01:00
Daniel Marjamäki ae001d4336 Fixed #8957 (Tokenizer::setVarId: varid not set when lambda function is used) 2019-02-03 08:57:04 +01:00
Daniel Marjamäki 4457faa26b Fixed #8850 (Array in-class initialization for private member considered uninitialized) 2019-02-02 18:34:41 +01:00
Daniel Marjamäki 9d8f798aca Fixed #8951 (false postive: (style) The class 'x' does not have a constructor although it has private member variables.) 2019-02-02 18:25:26 +01:00
IOBYTE 5c0ec782f1 Add ability to time simplifyTemplates. (#1640) 2019-02-01 18:17:18 +01:00
IOBYTE d08aa666f6 template simplifier: fix crash on windows (#1639)
* template simplifier: fix crash on windows

Use right token when searching for template type alias to delete.

* template simplifier: fix a cppcheck warning
2019-02-01 06:59:49 +01:00
Daniel Marjamäki 8925299947 Attempt to fix MSVC compile issue 2019-02-01 00:09:07 +01:00
IOBYTE 98fc6d1d32 Fixed #8959 ("(debug) Unknown type 'x'" with using/alias) (#1635)
* Fixed #8959 ("(debug) Unknown type 'x'" with using/alias)

* fix cppcheck warning
2019-01-31 23:57:37 +01:00
Daniel Marjamäki 53967c83e9 Fixed compile error 2019-01-31 23:52:48 +01:00
Daniel Marjamäki 961f66baff Fixed #8820 (import GUI project)
This has basic handling of GUI projects. But further work will be needed to handle addons etc, the plan is that we will be able to run addons from the command line soon.
2019-01-31 20:40:21 +01:00
IOBYTE 05a3e6807b Fixed #8950 and #8952 (improve type alias support) (#1633)
* Fixed #8950 and #8952 (improve type alias support)

* fix travis build
2019-01-31 16:53:51 +01:00
Paul Fultz II c176775afb Avoid infinite recursion in getLifetimeVariable (#1634)
* Fix direct recursion

* Limit depth of getLifetimeVariable
2019-01-31 10:34:41 +01:00
rikardfalkeborn 7779a9186e Use valueflow in unsigned less than zero checker (#1630)
The unsigned less than zero checker looked for patterns like "<= 0".
Switching to use valueflow improves the checker in a few aspects.

First, it removes false positives where instead of 0, the code is using
0L, 0U, etc. Instead of having to hard code the different variants of 0,
valueflow handles this automatically. This fixes FPs on the form

	uint32_t value = 0xFUL;
	void f() {
  		if (value < 0u)
		{
			value = 0u;
		}
	}

where 0u was previously not recognized by the checker. This fixes #8836.

Morover, it makes it possible to handle templates properly. In commit
fa076598ad, all warnings inside templates
were made inconclusive, since the checker had no idea if "0" came from
a template parameter or not.

This makes it possible to not warn for the following case which was
reported as a FP in #3233

	template<int n> void foo(unsigned int x) {
	if (x <= n);
	}
	foo<0>();

but give a warning for the following case

	template<int n> void foo(unsigned int x) {
	if (x <= 0);
	}

Previously, both these cases gave inconclusive warnings.

Finally, it makes it possible to give warnings for the following code:

	void f(unsigned x) {
		int y = 0;
		if (x <= y) {}
	}

Also, previously, the checker for unsigned variables larger than 0, the
checker used the string of the astoperand. This meant that for code like
the following:

	void f(unsigned x, unsigned y) {
		if (x -y >= 0) {}
	}

cppcheck would output

	[unsigned-expression-positive.c] (style) Unsigned variable '-' can't be negative so it is unnecessary to test it.

using expressionString() instead gives a better error message

        [unsigned-expression-positive.c] (style) Unsigned expression 'x-z' can't be negative so it is unnecessary to test it.
2019-01-31 09:30:29 +01:00
Daniel Marjamäki 18e6a09739 astyle formatting
[ci skip]
2019-01-29 09:48:18 +01:00
Paul Fultz II 165a22ed0f Lifetime: Support analysis with functions that do not return a reference (#1632)
* Initial support for function return

* Add test case

* Add support for reference parameters

* Format
2019-01-29 09:47:52 +01:00
Daniel Marjamäki 54cebfaf94 Fixed #8392 (false positive: "Memory leak" with malloc in if) 2019-01-27 10:27:44 +01:00
IOBYTE 606ba4fc1a template simplifier: add forward declaration map to debug output (#1629)
* template simplifier: add forward declaration map to debug output

* template simplifier: add partial specialization flag

* template simplifier: add specialization map and partial specialization map to debug output
2019-01-27 07:46:27 +01:00
Daniel Marjamäki 2bba9ac78a Fixed #8948 (False Positive: Variable 'n' is assigned a value that is never used.) 2019-01-26 21:44:07 +01:00
Paul Fultz II d6aaf401df Lifetime: Follow functions that return references
This will now warn for cases like this:

```cpp
int& f(int& a) {
    return a;
}
int& hello() {
    int x = 0;
    return f(x);
}
```
2019-01-26 11:03:57 +01:00
IOBYTE 68bbe15116 template simplifier: fix missing instantiation (#1627) 2019-01-26 07:08:54 +01:00
IOBYTE cb1a1df0fa template simplifier: fix out of line member function scope and use more full name matching (#1617) 2019-01-24 07:21:22 +01:00
IOBYTE ec8bc785a2 template simplifier: add support for using namespace when instantiating templates (#1615) 2019-01-23 08:53:01 +01:00
Paul Fultz II 3975913637 Extend lifetime checking for references
This will use the lifetime checker for dangling references. It will find these cases for indirectly assigned reference:

```cpp
int &foo()
{
    int s = 0;
    int& x = s;
    return x;
}
```

This will also fix issue 510 as well:

```cpp
int &f( int k )
{
    static int &r = k;
    return r;
}
```
2019-01-23 07:29:16 +01:00
Daniel Marjamäki 8c07be136a Fixed #8949 (False Positive: Variable 'f' is assigned a value that is never used.) 2019-01-22 21:16:27 +01:00
Daniel Marjamäki 149d688e9a Fix return value from ErrorLogger::reportUnmatchedSuppressions 2019-01-22 06:45:22 +01:00
Daniel Marjamäki 4119cfd3d1 Correct exit code when there are no unmatched suppressions 2019-01-21 20:33:22 +01:00
Paul Fultz II 4b37f276c2 ValueFlow: Set arrays to true when converting to a boolean
This sets it by checking the parent. It doesn't handle function parameters yet.
2019-01-21 20:05:35 +01:00
Daniel Marjamäki 91435310cb Fixed #8925 (compile_commands.json: False positives in .mm (Objective-C++) files, that file type should maybe just be ignored) 2019-01-21 06:36:31 +01:00
Daniel Marjamäki a26287f491 Fix Token::findExpressionStartEndTokens() regression 2019-01-20 13:23:19 +01:00
Daniel Marjamäki 8da4e31c42 Fixed #8941 (False Positive: Variable 'f' is assigned a value that is never used.) 2019-01-20 13:20:23 +01:00
IOBYTE 1acbdde302 Fixed #7417 ("syntax error" in valid code containing explicitly specialised variable template) (#1604) 2019-01-18 21:12:39 +01:00
Sebastian 4b1544d33b
library.cpp: Let tinyxml2 print a helpful error message when XML is bad (#1609)
In case the XML code of a library configuration is invalid Cppcheck now additionally prints out some helpful error description like this:
"Error=XML_ERROR_MISMATCHED_ELEMENT ErrorID=16 (0x10) Line number=304: XMLElement name=noreturn"
2019-01-18 17:10:41 +01:00
Lauri Nurmi 3bbd9fc9a4 Replace "virtual method" with "virtual function" in messages.
The term "method" is not really a part of C++ terminology.
2019-01-15 06:22:14 +01:00
Lauri Nurmi f267900257 Fix spelling of "overridden" in function names.
One 'd' was missing.
2019-01-15 06:22:14 +01:00
Robert Reif 6ef8dad459 template simplifier: improve namespace matching
* out of line member functions are a namespace
* template<...> and *_cast<> can't be instantiations
* refactor code to use less function parameters
* fix instantiation scopes
* use full name with namespace when available
* fallback to just matching names when full name doesn't match
2019-01-14 21:32:58 +01:00
IOBYTE f0cfe03f7b template simplifier: add cli --debug-template option to print the parsed template information (#1598) 2019-01-14 08:29:32 +01:00
Daniel Marjamäki 51afcb2f64 Fix Cppcheck missingOverride warnings 2019-01-13 13:22:36 +01:00
Daniel Marjamäki 0c08503b00 Travis: Enable missingOverride checker 2019-01-13 12:21:01 +01:00
Daniel Marjamäki 5f198662ff rephraze internal warning 2019-01-13 12:12:07 +01:00
Daniel Marjamäki c75a2265c0 Fix inline suppression. 2019-01-13 12:10:26 +01:00
Daniel Marjamäki 43035ff186 Remove inline suppression. The Cppcheck warning was a true positive. 2019-01-13 08:42:48 +01:00
Daniel Marjamäki d50c3de740 Remove inline suppression and fix false positive. 2019-01-13 07:59:41 +01:00
Daniel Marjamäki e6edd74099 Temporarily suppress Cppcheck false positives 2019-01-12 19:11:44 +01:00
Daniel Marjamäki d40314b825 Replace Token::Match with Token::simpleMatch for simple patterns
[ci skip]
2019-01-12 18:44:48 +01:00
Daniel Marjamäki 2b1b8f8fe9 Fix Cppcheck warnings
[ci skip]
2019-01-12 18:29:08 +01:00
Daniel Marjamäki 1cd16cf94f Suppressions: Handle comment in file that starts with # 2019-01-12 15:21:47 +01:00
Daniel Marjamäki 8b5f36670a Introduce macro OVERRIDE for gcc-4.6 compatibility. 2019-01-12 07:37:42 +01:00
Daniel Marjamäki c6b48b67f9 astyle formatting
[ci skip]
2019-01-11 16:37:12 +01:00
juremenart 45def06d59 fix trailing / from CMAKE JSON file and update unittests to cover both (w and w/o cases) (#1592)
* fix for CMake compile_commands.json input - director does not include trailing / which makes include directories wrong - so add it if it doesnt exist

* fix the bugfix for trailing / in the directory name of CMAKE JSON file, add also new test case to see if it works in both cases (with and without trailing /)

* revert adding accidental new line
2019-01-11 16:36:55 +01:00
versat 991191450a astyle formatting
[ci skip]
2019-01-11 12:56:31 +01:00
Paul Fultz II 921f6e4313 Fix issue 8883: False positive: returnDanglingLifetime with local struct or class (#1585) 2019-01-11 09:51:02 +01:00
Paul Fultz II 5fa956a597 Fix issue 8932: False positive knownConditionTrueFalse - valueflow ignores operator < (#1584) 2019-01-11 08:39:23 +01:00
Daniel Marjamäki 8509159d1a Uninitialized Member variable: Fixed FP when delegate constructor is used 2019-01-10 20:13:37 +01:00
rikardfalkeborn a48c8abcda Fix 8124: False positive va_end missing with lambda (#1577)
Skip lambdas, to avoid false positives due to possible
return statements in lambdas.

Also, run dmake.
2019-01-10 18:32:17 +01:00
Paul Fultz II 4e147a4c59 Add a check for duplicate if statements
This will warn for this:

```cpp
int f(int val)
{
	int i = 0;
	if( val & 0xff)
		i = 1;
	if( val & 0xff)
		i = 1;
        return i;
}
```
2019-01-09 20:41:01 +01:00
Daniel Marjamäki 35e56942d1 Fixed #8116 ([False positive] Invalid memory leak detection when using reference.) 2019-01-09 20:38:32 +01:00
Daniel Marjamäki 75e367c48b Fixed #8340 (incorrect memleak errors) 2019-01-09 19:50:41 +01:00
ivangalkin 5ddc6c64d7 CheckStl: add missing error ID iterators2 (#1576)
due to equal arguments...

  * iterators1 (`CheckStl::iteratorsError(const Token*, const std::string&, const std::string&)`) and
  * iterators2 (`CheckStl::iteratorsError(const Token*, const Token*, const std::string&, const std::string&)`)

... produced equal messages. Equal messages were filtered-out `CppCheck::reportErr(const ErrorLogger::ErrorMessage&)`.
So the error iterators2 disapeared from the error list.
2019-01-09 06:45:38 +01:00