Commit Graph

8653 Commits

Author SHA1 Message Date
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
IOBYTE 7875555b03 Fixed #6183 (TemplateSimplifier: Does not handle methods) (#1540) 2018-12-24 07:25:11 +01:00
orbitcowboy 611eb81302 Fixed checkcfg: test/cfg/std.cpp:2904:error:uninitvar:Uninitialized variable: s 2018-12-23 18:09:55 +01:00
Daniel Marjamäki b79619832e Clarify warning 2018-12-23 12:42:18 +01:00
Daniel Marjamäki e6e3987935 snprintf/g_snprintf: do not allow uninitialized target buffer 2018-12-22 20:40:47 +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
Rikard Falkeborn 204ce795ba Print test case name in assert
I sometimes find myself wondering which test cases I have broken when I fiddle with some check (since I then can try running these specific tests in the debugger, or make a small change and see if the tests pass). This PR adds the testclass and the test case names to the file and line number. I took special care to cover the case where an assert would be placed directly in the ```run()```-function, i.e., not inside a test case (from what I could see, no such case exists). If there is no need to handle this case, the code can be simplified (there wouldn't be need for the ```teardownTest()```-function for example).

The exact format for how to print the test name is very much up for discussion.
2018-12-21 13:55:24 +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
amai2012 0f4eac657d Make script less verbose 2018-12-19 22:18:24 +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
amai2012 378ffed37e Address compiler warning 2018-12-19 14:39:04 +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 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 357e2fbfb3 Add testcase for #8807 (False negative: Redundant variable assignments (loop)) 2018-12-16 21:45:26 +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 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 9742c1e2ae make checkcfg: Try to fix inline suppressions 2018-12-14 13:51:03 +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
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
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 01d0199ecf Fix testrunner 2018-12-04 19:56:22 +01:00