Commit Graph

10256 Commits

Author SHA1 Message Date
Daniel Marjamäki e4525d56a0 Fixed #8111 (performance warning - member variable at constructor) 2019-01-07 21:26:58 +01:00
IOBYTE 07da4b4d37 template simplifier: Add flag variable to cache information about dec… (#1569)
* template simplifier: Add flag variable to cache information about declarations.

Also fix some cppcheck warnings.

* Make variable const.
2019-01-07 06:55:22 +01:00
practicalswift 0a1b3a9d6f Fix typos (#1568) 2019-01-06 17:15:57 +01:00
Daniel Marjamäki 5636497c0b Fixed #8863 (false positive: (warning) Accessing an item in container 's'. Either the condition 's.empty()' is redundant or 's' can be empty.) 2019-01-06 12:21:55 +01:00
Daniel Marjamäki ea0232653f Fixed #8563 (CPPCheck not able to locate file through compilation database) 2019-01-05 23:11:43 +01:00
IOBYTE 817c748e4d Fixed #5953 (debug: varid0: Function::addArguments) (#1567) 2019-01-05 19:42:04 +01:00
Daniel Marjamäki 36ffa91825 Replace std::set::emplace with std::set::insert to make Cppcheck compilable in Slackware 14.0 2019-01-05 18:18:15 +01:00
Daniel Marjamäki 5f5c33baf2 Json: Use simple json library picojson to read compile databases 2019-01-05 17:45:07 +01:00
Daniel Marjamäki 615903c6be Improve syntax errors for unmatched (){}[] 2019-01-05 11:56:21 +01:00
IOBYTE 32a5d66e5b Fixed #8927 (SIGSEGV below TemplateSimplifier::expandTemplate) (#1564) 2019-01-05 11:14:09 +01:00
Paul Fultz II bba6dfb8b2 Fix issue 4744: ValueFlow: known integer result
This fixes valueflow to have a value for `||` operator here:

```cpp
bool f()
{
	bool a = (4 == 3); // <-- 0
	bool b = (3 == 3); // <-- 1
	return a || b; // <-- 1
}
```
2019-01-03 07:05:31 +01:00
Daniel Marjamäki 2b63997c2c Fixed #8928 (false positive: (style) Variable 'x' is assigned a value that is never used.) 2019-01-02 20:23:02 +01:00
Daniel Marjamäki 39ceb53578 Comment out code in valueFlowArray. There was too many false positives. 2019-01-02 19:57:11 +01:00
Daniel Marjamäki 39a96a5a16 ValueFlow: Temporarily comment out valueFlowTerminatingCondition 2019-01-02 19:42:08 +01:00
Daniel Marjamäki 7a40b85531 Fixed #8906 (Encoding error in XML message: info attribute) 2019-01-02 18:22:12 +01:00
amai2012 af639e9848
#7772 Add uninitMemberVarPrivate to errorlist (#1557) 2019-01-02 18:08:39 +01:00
Daniel Marjamäki 236c88151f Fixed #8926 (false positive: (style) Condition 's.x<=y' is always true) 2019-01-02 18:05:55 +01:00
IOBYTE 3b9828a132 template simplifier: fix crash on daca c++-annotations project (#1556)
Fix scope info bug on derived template class which caused a use after
free crash when deleting a template forward declaration in a different
scope.
2019-01-02 07:15:45 +01:00
Daniel Marjamäki 19514331fb Fixed #8907 (unknown macro not detected) 2019-01-01 19:30:13 +01:00
Daniel Marjamäki 115be7dfc8 ValueFlow: better FwdAnalysis for complex expressions 2019-01-01 18:23:47 +01:00
Daniel Marjamäki be7afac875 ValueFlow: remove handling of == for complex expressions it did not work properly 2019-01-01 17:23:46 +01:00
Daniel Marjamäki 20436ea986 Fix compiler warning 2019-01-01 17:04:47 +01:00
rikardfalkeborn 13ffefc8b8 Valueflow: Fix right shift with more than 31 bits (#1553)
When comparing if the shift is large enough to make the result zero, use
an unsigned long long to make sure the result fits. Also, a check that
avoids setting the value if the shift is equal to or larger than the
number of bits in the operand (this is undefined behaviour). Finally,
add a check to make sure the calculated value is not too large to store.

Add test cases to cover this.

This was detected by an MSVC warning.

valueflow.cpp(1350): warning C4334: '<<' : result of 32-bit shift implicitly
                     converted to 64 bits (was 64-bit shift intended?)
2019-01-01 14:15:50 +01:00
Daniel Marjamäki a73e989d1a isConstVarExpression: Fix FPs when there is C++ cast 2019-01-01 11:34:44 +01:00
Daniel Marjamäki 04d3672bde Fixed #7203 (Better syntax error, handle array declaration with @) 2019-01-01 09:45:41 +01:00
IOBYTE c37b807613 template simplifier: also check if instantiated template is not specialized (#1551) 2018-12-31 21:29:53 +01:00
Daniel Marjamäki ac357a96f7 Fixed #7384 (confuses syntax with variable name / "variable '(' is less than zero") 2018-12-31 18:36:06 +01:00
Daniel Marjamäki ed514644b8 Renamed FwdAnalysisAllPaths to FwdAnalysis 2018-12-31 18:00:47 +01:00
Daniel Marjamäki 4918a18bfb ValueFlow: Value of expression after condition 2018-12-31 17:37:38 +01:00
IOBYTE 9dc8faa3b6 template simplifier: fix location of forward declaration for explicit specializations (#1550) 2018-12-31 17:19:34 +01:00
Daniel Marjamäki 141ce7cd63 ValueFlow: Use FwdAnalysisAllPaths in ValueFlow to track complex expressions 2018-12-31 17:05:46 +01:00
Daniel Marjamäki fd8f599802 CTU: Use column in function id 2018-12-31 10:18:28 +01:00
Daniel Marjamäki aa4f61acdf CTU: Avoid FP in else block 2018-12-31 08:24:39 +01:00
Daniel Marjamäki fb6a291370 CTU: Avoid FP in code protected by &&,||,? 2018-12-31 08:16:21 +01:00
Daniel Marjamäki a520a41e64 CheckUninitVar: Try to report all CTU issues not just the first found issue 2018-12-31 07:54:00 +01:00
Daniel Marjamäki 37a3544ff5 CheckNullPointer: Try to report all CTU issues not just the first found issue 2018-12-31 07:52:14 +01:00
Daniel Marjamäki 5cc61e55f9 CTU: Refactoring; Use ValueFlow::Value::errorSeverity 2018-12-31 07:50:02 +01:00
amai2012 f2d7cb3ab6 Fix VS compiler warning and add a const 2018-12-30 22:17:21 +01:00
IOBYTE 36dfa0f27a template simplifier: refactor to use cached information (#1548)
* use already cached name token rather than recalculating it
  multiple times

* cache end of template parameters token and use it rather than
  recalculating it multiple times

* remove unnecessary end of template token and name token checks

* remove function parameter that is already contained in another
  parameter
2018-12-30 21:16:11 +01:00
Daniel Marjamäki 6b49a784c5 Fixed #8911 (Regression: False positive: Unassigned variable (alias)) 2018-12-30 20:20:20 +01:00
amai2012 73fa941352 Doxygen fixes 2018-12-30 19:31:50 +01:00
Daniel Marjamäki 91a580cbd7 CTU: more warnings 2018-12-30 18:31:37 +01:00
Daniel Marjamäki c8901e9bab CTU: Find paths better 2018-12-30 16:23:25 +01:00
Daniel Marjamäki b3fcd8a685 astyle formatting
[ci skip]
2018-12-30 11:59:06 +01:00
Daniel Marjamäki 378e083585 CTU: Refactoring the xml load/write. Renamed members. 2018-12-30 11:55:39 +01:00
Carlo Marcelo Arenas Belón 5ae6861a0f clang warnings (#1547)
* valueflow: remove unused variable known

since e4677ae640 will trigger :

lib/valueflow.cpp:506:20: warning: unused variable 'known' [-Wunused-variable]
        const bool known = (parent->astOperand1()->hasKnownValue() ||

* templatesimplifier: cleanup

since 48c960f56c showing:

lib/templatesimplifier.h:279:16: warning: private field 'mTokenizer' is not used
      [-Wunused-private-field]
    Tokenizer *mTokenizer;
2018-12-30 11:32:48 +01:00
ivangalkin 3f318548e2 CheckNullPointer: Add missing id 'nullPointerArithmeticRedundantCheck' to errorlist (#1535)
* split CheckNullPointer::arithmeticError() into
  * CheckNullPointer::pointerArithmeticError() and
  * CheckNullPointer::redundantConditionWarning()

* Additional errorlist entry:

```XML
<error id="nullPointerArithmeticRedundantCheck"
  severity="warning"
  msg="Either the condition is redundant or there is pointer arithmetic with NULL pointer."
  verbose="Either the condition is redundant or there is pointer arithmetic with NULL pointer." cwe="682"/>
```
2018-12-29 21:34:22 +01:00
IOBYTE da91ce2016 Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1546)
* Fixed #6183 (TemplateSimplifier: Does not handle methods)

* Fix function lookup.
2018-12-29 11:19:53 +01:00
Paul Fultz II e4677ae640 Fix issue 8910: Regression: ValueFlow: wrong conditional tokvalue
This fixes issue in:

```cpp
void f()
{
    char stack[512];
    RGNDATA *data;

    if (data_size > sizeof (stack))
        data = malloc (data_size);
    else
        data = (RGNDATA *)stack;

    if ((char *)data != stack)
            free (data); // <- data is not stack
}
```

It seems the `ProgramMemory` can't handle two known values(such as int and tok) together. So instead `ValueFlowAfterAssign` runs `ValueFlowForward` with tok values and then runs it with the other values.
2018-12-29 09:31:21 +01:00
Daniel Marjamäki d18f5d8709 CTU: Reuse CheckNullPointer::isPointerDeRef in the nullpointer isUnsafeUsage 2018-12-29 09:26:57 +01:00