Commit Graph

10652 Commits

Author SHA1 Message Date
Rikard Falkeborn ada881ccdf Fix #9130 (FP memory leak with NULL pointer cast) (#1839) 2019-05-18 06:22:25 +02:00
Paul Fultz II cf3515ee61 Fix issue 7372: False positive uninitMemberVar - on template specialization
This fixes the issue by skipping diagnostics when the symbols are incomplete in the constructor.
2019-05-17 20:24:41 +02:00
Carlo Marcelo Arenas Belón bf5c71bdca sync (#1835)
* build: remove -Wabi and add -Wundef

gcc >= 8 throws a warning about -Wabi (without a specific ABI version)
being ignored, while -Wundef seems more useful (as shown by the change
in config.h, which was probably an unfortunate typo)

travis.yaml should probably be updated soon, but was left out from this
change as the current images don't yet need it

* lib: unused function in valueflow

refactored out since 8c03be3212

lib/valueflow.cpp:3124:21: warning: unused function 'endTemplateArgument' [-Wunused-function]

* readme: include picojson

* make: also clean exe
2019-05-17 09:31:41 +02:00
Daniel Marjamäki 57c6628732 Revert 'Cleaning up unsimplified templates'. This fix caused problems. 2019-05-16 21:11:04 +02:00
Daniel Marjamäki 34cf62452e Change approach for Tokenizer::createLinks2: assume that <> should be linked 2019-05-16 20:50:56 +02:00
Daniel Marjamäki 0144db2490 Fixed 'Syntax Error' when < link is not set properly 2019-05-15 21:34:56 +02:00
Daniel Marjamäki 21ec78d8a1 Fix typo: %stype% => %type% 2019-05-15 09:06:27 +02:00
Daniel Marjamäki 79bb22f038 Fixed #9131 (Tokenizer::createLinks2; using std::list; list<config_option*> stack;) 2019-05-14 20:30:02 +02:00
Paul Fultz II 4e94c64da8 Fix issue 9099 and 9102: Incorrect valueflow for global variables (#1832) 2019-05-14 08:58:27 +02:00
Paul Fultz II 195da2b3d2 Fix issue 8993: False positive duplicateCondition related to auto (#1831) 2019-05-14 08:57:36 +02:00
Rikard Falkeborn dc0e8c214e Fix #9128 (FP in return non bool with class declared in function) (#1830)
Also break up the tests to smaller tests.
2019-05-14 08:56:28 +02:00
Daniel Marjamäki 9f00149674 Fixed #9127 (ast: wrong ast after using and template instantiation) 2019-05-12 17:24:42 +02:00
Daniel Marjamäki 27fad38e00 Fixed #9084 (Tokenizer::setVarId: Same varid for member variable and argument, unknown template type) 2019-05-12 09:10:37 +02:00
Daniel Marjamäki 4d9b1e6c3d Fixed #9094 (Tokenizer::createLinks2 problem with 'x%x<--a==x>x') 2019-05-11 19:11:40 +02:00
Daniel Marjamäki 1e2f1bac1f Fixed #8921 (Broken AST - mem = (void*)(new char)) 2019-05-11 15:50:30 +02:00
Daniel Marjamäki d58d4273f9 Cleaning up unsimplified templates 2019-05-11 13:00:03 +02:00
IOBYTE eade2bb2c2 Add support for simplifying user defined literal operator. (#1827) 2019-05-09 09:52:18 +02:00
Daniel Marjamäki a7478bcb5a Add missing include 2019-05-09 06:55:36 +02:00
Daniel Marjamäki 66b2b31eb0 Fix a few useStlAlgorithm warnings 2019-05-08 20:23:32 +02:00
adamjrichter 47ce998e6e lib: Separate statements of the form "assert(a && b)" into "assert(a)" and "assert(b)", for more precise diagnostics. (#1825) 2019-05-07 10:28:31 +02:00
IOBYTE 5364c6055f template simplifier: fix cppcheck warning (#1824) 2019-05-07 10:26:41 +02:00
IOBYTE baeae95bac template simplifier: fix a template alias TODO test (#1823) 2019-05-06 19:06:46 +02:00
Daniel Marjamäki f6527fcd9b fixed tests, unused templates are removed by default 2019-05-05 19:40:58 +02:00
Daniel Marjamäki c997186794 Only check unused templates if that is configured 2019-05-05 14:40:30 +02:00
Daniel Marjamäki 7efcb3cfe3 astyle formatting
[ci skip]
2019-05-05 11:41:29 +02:00
Paul Fultz II 8c03be3212 Fix issue 9077: False positive: Returning pointer to local variable (#1821)
* Avoid implicit conversion for lifetimes

* Fix issue 9077

* Add more tests

* Rename function

* Fix implicit conversion with containers

* Format

* Fix crash
2019-05-05 11:40:59 +02:00
Daniel Marjamäki fe04c15c9e CheckStl: Modernize the recommendations. string::starts_with is more intuitive than string::compare 2019-05-05 10:35:44 +02:00
Paul Fultz II a688df0ea1 Fix issue 9120: crash in valueflow (#1822) 2019-05-05 09:51:36 +02:00
Daniel Marjamäki 0b3342abe5 Fix Cppcheck warning 2019-05-04 20:41:43 +02:00
Daniel Marjamäki 45a343ac2d Fixed #8795 (Syntax Error: AST broken, binary operator '||' doesn't have two operands) 2019-05-04 19:05:03 +02:00
Daniel Marjamäki d1bb0465b8 Fixed 2 Cppcheck warnings 2019-05-04 11:58:03 +02:00
Daniel Marjamäki 604a13a22b rename parameter 2019-05-04 10:36:49 +02:00
Paul Fultz II 091f4bcf8d Add check for unnecessary search before insertion
This will warn for cases where searching in an associative container happens before insertion, like this:

```cpp
void f1(std::set<unsigned>& s, unsigned x) {
    if (s.find(x) == s.end()) {
        s.insert(x);
    }
}

void f2(std::map<unsigned, unsigned>& m, unsigned x) {
    if (m.find(x) == m.end()) {
        m.emplace(x, 1);
    } else {
        m[x] = 1;
    }
}
```

In the case of the map it could be written as `m[x] = 1` as it will create the key if it doesnt exist, so the extra search is not necessary.

I have this marked as `performance` as it is mostly concerning performance, but there could be a copy-paste error possibly, although I dont think thats common.
2019-05-02 11:04:23 +02:00
Rikard Falkeborn 4edc248dae Fix 8840: Don't warn when returning a bitmask as bool (#1818)
A common pattern is to have a function like similar to this:

	bool isFlagSet(uint32_t f) {
		return f & 0x4;
	}

Warning that the function returns a non-boolean in this case is too
noisy, it would be better suited for a Misra check, so remove the
warnings in the most obvious cases.
2019-05-02 07:00:27 +02:00
Daniel Marjamäki 6c3c090403 Fixed #6317 (wrong simplification: int i = 1.5; return i; get simplified to: return 1.5;) 2019-05-01 17:05:16 +02:00
Rikard Falkeborn 1cc5f3abe7 Set wchar_t type (#1807)
This is necessary for valueflow to know the size, for example when
calculating sizeof(wchar_t).
2019-05-01 16:34:28 +02:00
Daniel Marjamäki 6da42a3d63 Fixed #9112 (false positive: (error) Array index out of bounds; buffer 'x' is accessed at offset n.) 2019-05-01 13:00:14 +02:00
Daniel Marjamäki b3a46e72dc Fix and test syntaxError suppression 2019-05-01 11:54:13 +02:00
Paul Fultz II 71bd7f68d4 Fix bug in lifetime constructors (#1816) 2019-05-01 07:52:52 +02:00
Daniel Marjamäki 66064fb2bb Disable valueFlowGlobalConstVar until #9099 is fixed 2019-04-30 20:51:59 +02:00
Daniel Marjamäki 1d12136b59 Fixed Cppcheck uninitStructMember warnings 2019-04-30 20:45:48 +02:00
Daniel Marjamäki 41cf13bb7e Fixed #error in self check when __CPPCHECK__ is defined 2019-04-30 20:31:46 +02:00
Daniel Marjamäki d69f002757 Fixed Cppcheck shadowVar warning 2019-04-30 20:19:21 +02:00
Rikard Falkeborn c7d7f8738c Optimize astStringVerbose() for large arrays (#1815)
Change the astStringVerbose() recursion to extend a string instead of
returning one. This has the benefit that for tokens where the recursion
runs deep (typically large arrays), the time savings can be substantial
(see comments on benchmarks further down).

The reason is that previously, for each token, the astString of its
operands was constructed, and then appended to this tokens astString.
This led to a lot of unnecessary string copying (and with that
allocations). Instead, by passing the string by reference, the number
of temporary strings is greatly reduced.

Another way of seeing it is that previously, the string was constructed
from end to beginning, but now it is constructed from the beginning to
end. There was no notable speedup by preallocating the entire string
using string::reserve() (at least not on Linux).

To benchmark, the changes and master were tested on Linux using the
commands:

	make
	time cppcheck --debug --verbose $file >/dev/null

i.e., the cppcheck binary was compiled with the settings in the
Makefile. Printing the output to screen or file will of course take
longer time.

In Trac ticket #8355 which triggered this change, an example file from the
Wine repository was attached. Running the above cppcheck on master took
24 minutes and with the changes in this commmit, took 22 seconds.

Another test made was on lib/tokenlist.cpp in the cppcheck repo, which is
more "normal" file. On that file there was no measurable time difference.

A synthetic benchmark was generated to illustrate the effects on dumping
the ast for arrays of different sizes. The generate code looked as
follows:

	const int array[] = {...};

with different number of elements. The results are as follows (times are
in seconds):

	N	master optimized
	10	0.1    0.1
	100	0.1    0.1
	1000	2.8    0.7
	2000	19     1.8
	3000	53     3.8
	5000	350    10
	10000	3215   38

As we can see, for small arrays, there is no time difference, but for
large arrays the time savings are substantial.
2019-04-30 13:35:48 +02:00
IOBYTE 505b7f7ebd Fixed #9110 (Syntax error on valid C++ code) (#1813) 2019-04-29 15:17:37 +02:00
Paul Fultz II ae8a3aae8d Fix FP with unused variable (#1814) 2019-04-29 11:50:19 +02:00
Daniel Marjamäki 2e694f38c8 Refactoring; Use const reference instead of const 2019-04-29 08:53:36 +02:00
Daniel Marjamäki 45e5edce16 Fixed Cppcheck shadowVariable warning 2019-04-28 12:04:44 +02:00
Daniel Marjamäki 74fad6ce05 Modernizing; Use std::accumulate instead of for loop 2019-04-28 11:25:43 +02:00
Daniel Marjamäki 9c5d24c551 Modernizing: Use std::accumulate instead of for loop 2019-04-28 11:17:11 +02:00