Commit Graph

10229 Commits

Author SHA1 Message Date
amai2012 378ffed37e Address compiler warning 2018-12-19 14:39:04 +01:00
PKEuS 34874dd94f Optimization: Removed unnecessary calls to simplifyPath(). The Caller should do this, and our callers (mainly the test suite) more or less do so, as they all supply just dummy paths ("test.cpp") 2018-12-18 20:33:45 +01:00
Daniel Marjamäki bc34f0239d Disable the subfunction value flow analysis. It does not work well and needs to be rewritten. There are false positives. 2018-12-18 14:36:49 +01:00
Paul Fultz II 34330b51d1 Fix issue 8905: Condition 'a==0' is always false
This fixes the FP in:

```cpp
void f(const int a[]){ if (a == 0){} }
```
2018-12-18 08:16:43 +01:00
IOBYTE 1cba78090c Fix const anonymous struct. (#1527) 2018-12-18 08:15:12 +01:00
Daniel Marjamäki 0f63874c62 Take back the whole program analysis for null pointers and uninitialized variables 2018-12-18 07:56:33 +01:00
Daniel Marjamäki 643ddd4caa Code cleanup 2018-12-17 18:54:32 +01:00
Daniel Marjamäki 3b328f9187 CheckMemoryLeak: Cleanup the old memory leaks check 2018-12-17 18:12:50 +01:00
Daniel Marjamäki f118c22bb6 CheckUnusedVar: Cleanup checker 2018-12-17 17:48:45 +01:00
Daniel Marjamäki cf09fd6274 CheckUnusedVar: Code cleanup 2018-12-17 17:28:15 +01:00
Daniel Marjamäki fe38e256cc Fixed #7907 (FN: redundant assignment inside switchcase, overwritten by assignment outside of switch) 2018-12-17 16:10:47 +01:00
Daniel Marjamäki bf4e850e11 Fixed #4475 (New check: struct member is assigned a value that is not read) 2018-12-17 15:40:15 +01:00
Daniel Marjamäki 858d9a18a7 Fixed #3857 (false negative: (style) Variable 'var' is assigned a value that is never used) 2018-12-17 15:16:47 +01:00
Paul Fultz II 025881cf35 Fix issue 8829: Condition '...' is always true (int buf[42]; if(buf != NULL){})
This makes arrays non-null in valueflow, so it can catch comparisons against null that is always true:

```cpp
void f(void) {
   int buf[42];
   if( buf != 0) {;} // << always true
}
```
2018-12-17 06:07:34 +01:00
Paul Fultz II 9b973e652c Issue 8830: New check: Function argument evaluates to constant value
Add a check for function arguments that can be constant:

```cpp
extern void bar(int);
void f(int x) {
   bar((x & 0x01) >> 7); // function 'bar' is always called with a '0'-argument
}
```
2018-12-17 06:04:24 +01:00
IOBYTE 2090866cd0 template simplifier: remove explicit instantiations after instantiation (#1523)
* template simplifier: remove explicit instantiations after instantiation

* Fix use after free crash in clang test suite.
2018-12-17 05:58:48 +01:00
Daniel Marjamäki c8d688607a Fixed #8901 (Unused value: const variable initialization) 2018-12-16 19:01:05 +01:00
Daniel Marjamäki 21eb1c5e22 FwdAnalysis: Fix false negatives for struct members 2018-12-16 18:32:34 +01:00
Daniel Marjamäki 46a0172480 FwdAnalysis: fix FP in loop 2018-12-16 16:43:04 +01:00
Daniel Marjamäki 97d2075007 FwdAnalysis: better handling of loops 2018-12-16 11:42:11 +01:00
Daniel Marjamäki 3af0d73f82 Unused value: Fixed false negatives for loops 2018-12-16 11:18:37 +01:00
Paul Fultz II 3262a3bebe Add isSameExpression to valueflow analysis
Check for same expressions in valueflow analysis.
2018-12-16 07:35:27 +01:00
Paul Fultz II 45dcfad9f9 Fix issue 8899: False positive returnDanglingLifetime when returning by value
This fixes the FP from:

```cpp
#include <string>

class MyString
{
        public:
        MyString(char* source)
        {
                length = strlen( source );
                buffer = new char[length+1];
                if( buffer )
                {
                        strcpy( buffer, source );
                }
        }

        char* buffer;
        int length;
};

MyString Foo()
{
        char arr[20];
        sprintf(arr, "hello world");

        return arr;
}

void main()
{
        MyString str = Foo();

        printf(str.buffer);
}
```
2018-12-15 17:58:45 +01:00
Daniel Marjamäki 1bfe98447a FwdAnalysis: Tweak possiblyAliased 2018-12-15 11:54:00 +01:00
Daniel Marjamäki f26549e5ab Fixed #8896 (Tokenizer: Anonymous struct) 2018-12-15 08:42:35 +01:00
IOBYTE a1c275436f Fix #8902 (Crash in TemplateSimplifier) (#1521) 2018-12-15 07:52:47 +01:00
Daniel Marjamäki 37416010ef Unused value: Fix false positive (ast, {}) 2018-12-14 18:56:09 +01:00
Paul Fultz II be6782d386 Fix FP 8891: Incorrect return scope when using uniform initialization
This fixes the FP in:

```cpp

std::string f(const std::string& data)
{
  if (data.empty())
    return {};

  data[0];
}
```
2018-12-14 18:31:10 +01:00
Daniel Marjamäki 8464085535 UnusedVariables: Fix FP for unknown variable 2018-12-13 21:37:21 +01:00
Daniel Marjamäki 092d434f91 UnusedVar: Fix FP for array arguments 2018-12-13 21:08:18 +01:00
Daniel Marjamäki 1f27cd56c0 FwdAnalysis; Code cleanup, isNullOperand 2018-12-13 21:01:33 +01:00
Daniel Marjamäki 0b4e08cac9 Use FwdAnalysis in UnusedVar. This is still work-in-progress. Merging to master branch so it can be tested. 2018-12-13 18:52:56 +01:00
IOBYTE 0f83aff3b8 Improve trailing return type support. (#1520)
* Improve trailing return type support.

* Partial fix for #8889 (varid on function when using trailing return type)

* Handle operators in templates.
2018-12-13 06:34:10 +01:00
Daniel Marjamäki e0b64ec7a9 Fixed #8884 (AST: handle xs... template argument) 2018-12-12 19:00:14 +01:00
amai2012 6924522475
Refactor methods for identification of numeric literals. (#1514) 2018-12-10 12:10:26 +01:00
PKEuS 886aa07ffb Set version to 1.86.99/1.87 dev 2018-12-08 11:53:37 +01:00
Daniel Marjamäki a16f694254 Revert "Fix issue 8884: Regression: False positive: Variable 'f' is reassigned a value before the old one has been used (#1513)"
This reverts commit 6953dddfa6.
2018-12-08 08:25:20 +01:00
Daniel Marjamäki 5e527bdd08 Update version 2018-12-08 08:17:05 +01:00
Paul Fultz II 6953dddfa6 Fix issue 8884: Regression: False positive: Variable 'f' is reassigned a value before the old one has been used (#1513) 2018-12-08 07:33:51 +01:00
amai2012 a68086c959
Implement hexadecimal float conversion in MathLib::toDoubleNumber ind… (#1506)
* Implement hexadecimal float conversion in MathLib::toDoubleNumber independent of C99/C++17
* Refactor MathLib::isFloatHex and cure some false results
2018-12-06 22:16:16 +01:00
IOBYTE a90c56ad76 Fixed #8880 (Regression: syntax error for valid C++ template code) (#1509) 2018-12-06 21:47:48 +01:00
Daniel Marjamäki bd0a935d8a Tokenizer: Improved handling of compiler extensions that use @ (see https://sourceforge.net/p/cppcheck/discussion/general/thread/8f618cb0a3) 2018-12-04 19:33:39 +01:00
Daniel Marjamäki 88c61e8d1e ValueFlow: Avoid FP when lambda is used 2018-12-04 18:54:26 +01:00
Daniel Marjamäki 452318dfa4 Remove FwdAnalysis::reads: It is not finished 2018-12-04 18:46:23 +01:00
Daniel Marjamäki f5a94ed300 ValueFlow: Fix FP when lambda is called 2018-12-04 18:46:00 +01:00
Daniel Marjamäki 49413b7d4c Tokenizer: Add simplifyAt to handle some nonstandard code with @ 2018-12-04 16:52:41 +01:00
Daniel Marjamäki 7ef8f60b07 Fixed #8817 (Change wording in performance/functionStatic) 2018-12-03 18:30:54 +01:00
Daniel Marjamäki c03c262058 Preparing FwdAnalysis for ValueFlow usage where we want to fetch read locations 2018-12-02 18:29:16 +01:00
Daniel Marjamäki d8fada6702 Refactoring FwdAnalysis 2018-12-02 17:42:18 +01:00
Daniel Marjamäki 6734571f06 Refactoring: Create FwdAnalysis class in astutils 2018-12-02 17:01:52 +01:00
Igor 61878c5e11 Add null pointer check to fix SEGFAULT (#1499)
* Add null pointer check to fix segfault

* Add first test case to reproduce problem
2018-12-02 14:36:01 +01:00
Paul Fultz II 3e1b34dd8f Fix FPs and crashes with byDerefCopy (#1503)
* Fix FP when inserting a range into a container

* Formatting

* Fix crash
2018-12-02 14:31:31 +01:00
Daniel Marjamäki ba564076db Fixed #7907 (FN: redundant assignment inside switchcase, overwritten by assignment outside of switch) 2018-12-02 14:04:59 +01:00
Daniel Marjamäki 88785dda02 Refactoring the redundant assignments check 2018-12-02 11:41:27 +01:00
Daniel Marjamäki 8087cfed5d Fixed #8627 (Tokenizer::setVarIdPass2: constructor parameter) 2018-12-02 09:28:05 +01:00
Paul Fultz II b841b818d2 Fix 8872: Crash in LifetimeStore when there is no scope for variable
This fixes crash in:

```cpp
struct edit_line_paste_over {
    void operator()(agi::Context *c) override {
        paste_lines(c, true, [&](AssDialogue *new_line) -> AssDialogue * {
            AssDialogue *ret = paste_over(c->parent, pasteOverOptions, new_line, static_cast<AssDialogue*>(&*pos));
            return ret;
          });
    }
};
```
2018-12-01 19:11:26 +01:00
Paul Fultz II 67dd822910 Fix FP in lifetime anlaysis: Dont decay std array
This will fix FP with:

```cpp
std::array<char, 1> f() {
    std::array<char, 1> x;
    return x;
}
```
2018-12-01 19:09:19 +01:00
Paul Fultz II 229c45e7f8 Fix issue 8865: FP with dangling lifetime
This fixes:

```cpp
void f(uint32_t event, unsigned long op, const xen_ulong_t *args)
{
    struct __packed {
        uint32_t op;
        uint32_t args[6];
    } d;
    uint32_t *a = d.args;
}
```
2018-12-01 19:07:46 +01:00
Daniel Marjamäki 2c803a1ead Revert "#6514 Try to support hexadecimal floating numbers in MathLib::toDoubleNumber"
This reverts commit a73decf7e4.
2018-12-01 19:01:51 +01:00
Daniel Marjamäki 3fadefe318 Revert "Add missing include"
This reverts commit a2b6eaf311.
2018-12-01 19:00:42 +01:00
Daniel Marjamäki 96929c53c0 Fixed #8873 (Add syntaxError when there is no RHS for +-) 2018-12-01 17:29:41 +01:00
Daniel Marjamäki f42648fe22 Fixed #8114 (false positive: Address of local auto-variable assigned to a function parameter.) 2018-12-01 10:11:02 +01:00
amai2012 a2b6eaf311 Add missing include 2018-12-01 01:36:04 +01:00
amai2012 a73decf7e4 #6514 Try to support hexadecimal floating numbers in MathLib::toDoubleNumber 2018-12-01 00:50:26 +01:00
Colomban Wendling cad4e4ab20 Fix handling of `sizeof &var` (#1498)
Fixes https://trac.cppcheck.net/ticket/8870
2018-11-30 13:53:58 +01:00
IOBYTE 3d024f3f6d template simplifier: fix function forward declaration bug for constructor with initializer list. (#1497) 2018-11-29 06:24:28 +01:00
Daniel Marjamäki ff469867e7 Refactor CheckStl::stlOutOfBounds 2018-11-28 20:30:58 +01:00
Daniel Marjamäki dd94bfede9 CheckStl: Improving checking of container access out of bounds 2018-11-28 19:27:28 +01:00
Daniel Marjamäki 6493db6ca2 Try to clarify message for container access out of bounds a little more. 2018-11-28 13:58:01 +01:00
Daniel Marjamäki 0f2f807798 Improve the container out of bounds messages. They are still not perfect. 2018-11-28 07:03:56 +01:00
Daniel Marjamäki 13c6489571 Redundant variable assignment: Fix FN for struct members 2018-11-27 18:22:22 +01:00
Daniel Marjamäki 32c05fef92 Redundant assignment: check that --enable=style has been used. 2018-11-27 13:04:50 +01:00
Daniel Marjamäki 0ad757fc78 valueFlowLifetime: Try to cleanup the loop a little. No functional change is intended. 2018-11-27 06:43:59 +01:00
Paul Fultz II 5a6f9ac82a Fix FP with strcmp and terminating conditions 2018-11-27 06:39:29 +01:00
IOBYTE f2660ed203 template simplifier: fix instantiated template names in forward declarations (#1495)
This now handles the revised example code in #8603.
2018-11-27 06:17:04 +01:00
Daniel Marjamäki 2887ee10c0 Fixed #8800 (Possible variable assignment ignored in boolean expression) 2018-11-26 14:00:03 +01:00
Daniel Marjamäki affd03f1d6 Minor tweak for redundantVariableAssignment 2018-11-26 11:16:50 +01:00
IOBYTE e20079a5d9 template simplifier: fix 3 function forward declaration bugs (#1493)
* fix support for multi token types
* fix support for const member functions
* fix duplicate template parameters sometimes being inserted
2018-11-26 06:23:12 +01:00
Daniel Marjamäki 86f9fb778b Fixed #8864 (compile commands: handle define with string value) 2018-11-25 15:09:23 +01:00
Daniel Marjamäki 0160f80ffe redundantVarAssignment: avoid FPs when loops are used 2018-11-25 10:32:30 +01:00
Daniel Marjamäki 22f736eae2 redundant variable assignments: avoid FPs for initializations 2018-11-25 08:49:09 +01:00
Daniel Marjamäki 2f66b31d43 redundantAssignmentInSwitch: fix false positive when there is goto 2018-11-24 21:39:01 +01:00
Paul Fultz II a3921ea861 Refactor valueFlowAfterCondition
So this unifies the `valueFlowAfterCondition` so it re-uses more code between checking for integers and container sizes. This should make valueFlowContainer more robust.

It also extends valueflow to support container comparisons such as `if (v.size() < 3)` or `if (v.size() > 3)` using the same mechanism that is used for integers.
2018-11-24 10:07:12 +01:00
Daniel Marjamäki 866688c70a Rewriting redundantAssignment checker 2018-11-24 10:03:54 +01:00
Daniel Marjamäki b049a31e7c Refactoring; Use visitAstNodes 2018-11-23 20:41:39 +01:00
Daniel Marjamäki 2b09354b05 Refactoring; use visitAstNodes 2018-11-23 20:33:31 +01:00
Daniel Marjamäki 2214ef5359 Refactor isVLAIndex 2018-11-23 20:23:20 +01:00
Daniel Marjamäki 8f164d9602 Refactoring; use visitAstNodes 2018-11-23 19:22:53 +01:00
Daniel Marjamäki 52f9650533 Refactoring: Use visitAstNodes 2018-11-23 19:16:19 +01:00
Daniel Marjamäki 745b58de26 Refactoring: Use visitAstNodes 2018-11-23 17:18:07 +01:00
IOBYTE 358f0c473d Modify template simplifier to add forward declarations of some templa… (#1489)
* Modify template simplifier to add forward declarations of some template functions so symbol database can make sense of the expanded templates.

* Fix travis.
2018-11-23 11:36:09 +01:00
Daniel Marjamäki ecb3c04fba astutils: Add function that visits nodes in AST tree 2018-11-23 06:53:43 +01:00
Paul Fultz II f16d9d7d90 Issue 6175: Check lifetime of a variables stored in containers and member variables
Cppcheck will now warn for all cases here:

```cpp
#include <vector>
class CCluster {};
class MyClass
{ public:
    std::vector<CCluster*> m_cluster;
    void createCluster()
    {
        CCluster cl;
        CCluster* pcl=&cl;
        m_cluster.push_back(pcl);
    }
    void createCluster2()
    {
        CCluster cl;
        m_cluster.push_back(&cl);
    }
    CCluster* Cluster()
    {
        CCluster cl;
        CCluster* pcl=&cl;
        return pcl;
    }
    CCluster* Cluster2()
    {
        CCluster cl;
        return &cl;
    }
};

```
2018-11-21 08:43:57 +01:00
Daniel Marjamäki 9d8e5e36eb Added a few TODO comments 2018-11-20 22:57:01 +01:00
Daniel Marjamäki 8227188786 comment out old memleak checking. maybe it can be removed. 2018-11-20 18:40:18 +01:00
Daniel Marjamäki a5af5b2d08 Revert "Fixed #7619 (False positive: Redundant assignment)"
There is a crash I need to look into.
2018-11-20 06:23:43 +01:00
Daniel Marjamäki c899792232 Fixed #7619 (False positive: Redundant assignment) 2018-11-19 21:23:36 +01:00
Daniel Marjamäki a8cbbe0e16 Fixed #8816 (FP shadowLocal - variable shadows a template function?) 2018-11-19 07:00:15 +01:00
Daniel Marjamäki 9ef3c79bc6 Fixed #8851 (Crash in valueFlowContainerForward (daca@home: pbbam)) 2018-11-18 20:18:55 +01:00
Daniel Marjamäki f2b26a488a relative paths: another fix for {code} 2018-11-18 16:15:09 +01:00