Commit Graph

10229 Commits

Author SHA1 Message Date
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
amai2012 03ed4afc70 Export interfaces from cppcheck-core.dll used from testrunner. In turn remove ctu sources from testrunner which are obsolete now. 2018-12-28 23:09:44 +01:00
Oliver Schode 22504975b9 Patch assert warning lib/checkassert.cpp (#1543)
* Fixed typo in warning about modified variable inside assertion

* Fixed assert warning again in checkassert.cpp
2018-12-28 15:25:22 +01:00
Daniel Marjamäki ee3fd0af03 Refactoring: Combine replaceStr functions 2018-12-28 13:11:54 +01:00
rikardfalkeborn 036fcf7827 Fix warnings (#1541)
* Fix reorder warning

* Fix override warnings

Clang warns about missing overrides.

* Remove unused function

* Add missing argument to function calls
2018-12-28 12:59:05 +01:00
amai2012 128ad96b59 Add ctu sources to VS projects 2018-12-27 22:11:40 +01:00
Daniel Marjamäki a40fe3c67f Fixed #7872 (ValueFlow: static_cast) 2018-12-27 21:33:01 +01:00
Daniel Marjamäki 6fef02498c Fixed #7263 (False negative: redundant assignment using +=) 2018-12-27 17:27:53 +01:00
Daniel Marjamäki a788512d66 CTU: Refactor isUnsafeFunction 2018-12-26 19:17:49 +01:00
Daniel Marjamäki a6e227a73c CTU: Refactoring; getErrorPath 2018-12-26 15:56:10 +01:00
Daniel Marjamäki e39be48c92 CTU: Refactoring, create ErrorPath in ctu 2018-12-26 11:36:26 +01:00
Daniel Marjamäki 271763e680 CTU: Refactoring 2018-12-25 21:11:23 +01:00
Daniel Marjamäki a1dca6acd5 Fix CTU nullpointer check 2018-12-25 12:04:01 +01:00
Daniel Marjamäki ddbe5c129c Clarify FwdAnalysis. It is useful for checks that need data flow analysis of ALL paths. 2018-12-25 11:56:06 +01:00
Daniel Marjamäki c7993df4ff Refactoring; Use range for loops 2018-12-25 11:47:45 +01:00
Daniel Marjamäki 162576146e Revert "Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1540)"
This reverts commit 7875555b03.
2018-12-24 20:10:00 +01:00
Daniel Marjamäki b3e6ecd827 Library: Make loading of cfg files more robust. Saw a problem to use --library=gtk when the current folder has a folder 'gtk' 2018-12-24 08:37:33 +01:00
IOBYTE 7875555b03 Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1540) 2018-12-24 07:25:11 +01:00
Daniel Marjamäki b79619832e Clarify warning 2018-12-23 12:42:18 +01:00
IOBYTE 48c960f56c template simplifier: better detection of template functions (#1539)
* template simplifier: better detection of template functions

* fix comment
2018-12-22 10:05:10 +01:00
Sebastian b51f19d530
Fix some doxygen warnings/issues in the comments (#1537) 2018-12-21 21:23:03 +01:00
Daniel Marjamäki b97b3b7ef8 astyle formatting
[ci skip]
2018-12-21 13:54:59 +01:00
rebnridgway 431d068339 Several fairly significant optimisations (#1518)
* Code changes for Token::mImpl optimisation

* Added new TokenImpl optimisation

Moving members to the TokenImpl struct reduces the size of the Token class, which is a fairly significant optimisation.  In my testing on Windows with 32-bit Release-PCRE, this change reduced the size of the Token class from 108 bits to 52 bits and reduced run-time of my test case by around 20%.

* Several optimisations

Deleted some code that ran very slowly and did nothing, as there is no need to change a Token's string to null if you are about to delete it.
Added a frontToken to simplifyCalculations to reduce the amount of work it has to do on already-simplified calculations.
Moved template removal to the end of the list as this reduces redundant iteration and saves time.

* Added tok argument to simplifyCalculations

This means callers can avoid unnecessary work if they know which tokens have already been simplified.  Passing nullptr indicates the original behaviour (starting from the front of the list).

* Removed mention of member from another change

* Re-added and optimised some code deleted in error

Changing mTemplateInstantiations to a vector avoids the high cost of doing repeated linear searches.  Changing how the code iterates through the array was necessary because the vector can be resized at several points during the loop, which breaks existing references and iterators.

* Changed mTemplateInstantiations to a vector

This is an optimisation that makes repeated linear searches of this collection significantly faster. 
Also added a copy constructor to TokenAndName so code can make copies of these objects to keep a reference if a vector gets resized.

* A cleaner optimisation to removing template tokens

This reverts the previous change to made mInstantiatedTemplates a vector and the iterator changes to support this, and makes mTypesUsedInTemplateInstantiation so the eraseTokens logic can be unified.

* Reverted vector to list

Also made mTypesUsedInTemplateInstantiation a vector of TokenAndName objects so it can share the same logic as the other members.

* Added member for template simplifier pointer

This can be used more efficiently than marking Tokens with a flag and then searching through all templates to find the one that matches.

* Turned loop inside out

This means we only have to iterate through the std::list once.  std::list is very expensive to iterate through.

* Latest code from danmar and fixed optimisations

In particular I have optimised simplifying template instantiation names as this was incredibly slow because of the number of times it had to iterate through the template instantiation list.  Previous optimisations to this weren't very effective and broke some edge cases.

* Added changes from danmar

Made mExplicitInstantiationsToDelete a vector of TokenAndName to be consistent with the rest of the members, which are cleaned up very efficiently.

* Tokens can have many templateSimplifierPointers

* templateSimplifierPointers must be kept in sync
2018-12-21 13:51:45 +01:00
Sebastian a1a695dcda checkio: Add missing id "invalidScanfFormatWidth_smaller" to errorlist output (#1533) 2018-12-20 21:14:02 +01:00
IOBYTE d528934139 template simplifier: also remove forward declarations when removing expanded templates (#1536) 2018-12-20 20:55:27 +01:00
amai2012 19e979315f
Correct detection of Microsoft extensions in MathLib::isValidIntegerSuffix. Remove public overloaded implementation which was not used outside mathlib.cpp. (#1531) 2018-12-20 12:20:31 +01:00
IOBYTE c31331d085 template simplifier: fix explicit instantiation with types starting with const and ending in * and &. (#1530) 2018-12-19 21:59:59 +01:00
Daniel Marjamäki e2c433a0f8 Fixed #8914 (False positive with unary_function argument) 2018-12-19 19:43:05 +01:00