Commit Graph

20191 Commits

Author SHA1 Message Date
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
Daniel Marjamäki f3167865ef Travis: Remove suppression for unsignedLessThanZero warnings 2019-05-01 07:54:30 +02:00
Paul Fultz II 71bd7f68d4 Fix bug in lifetime constructors (#1816) 2019-05-01 07:52:52 +02:00
Daniel Marjamäki 7260bdd6d8 Fixed Cppcheck shadowVar warnings 2019-04-30 21:01:18 +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
Daniel Marjamäki b0baf4f65b Travis: Fix the cppcheck self-check 2019-04-30 08:56:20 +02:00
Daniel Marjamäki 37656cdca1 Fix comment 2019-04-30 08:54:41 +02:00
Daniel Marjamäki 0053476bef Fix Cppcheck warnings 2019-04-30 01:46:02 +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
Daniel Marjamäki 9d72e24edb Refactoring; Use stl algorithm instead of for loop 2019-04-28 10:30:20 +02:00
Daniel Marjamäki f503386666 Refactoring; replace for loop with std::find_if 2019-04-28 10:07:11 +02:00
Daniel Marjamäki aaf1af6736 Fix Cppcheck passedByValue warning 2019-04-28 07:58:47 +02:00
Daniel Marjamäki 0e8f2cdf63 Use multiline in testing 2019-04-28 07:48:38 +02:00
Daniel Marjamäki fd4e371091 Refactoring: Use stl algorithm 2019-04-28 07:40:00 +02:00
Daniel Marjamäki 69faa0d8c8 Refactoring: Use STL algorithms 2019-04-28 07:30:17 +02:00
orbitcowboy c8dce14303 wxwidgets.cfg: Added support for more interfaces. 2019-04-27 18:36:48 +02:00
Daniel Marjamäki 48dfba429a Fixed #8822 (false positive: MISRA rule 13.4) 2019-04-27 17:43:26 +02:00
Daniel Marjamäki 004d7d5333 Fixed #8580 (False positive: unused function (lambda)) 2019-04-27 17:17:51 +02:00
Daniel Marjamäki 6fcef867a1 Refactoring; use range for loops 2019-04-27 17:04:14 +02:00
amai2012 b5ee9d97ef Move some signal constants from posix.cfg to std.cfg. Add some more interfaces to posix.cfg 2019-04-26 19:26:04 +02:00
orbitcowboy d724f86e01 gnu.cfg: Added support for tee(). Reference: http://man7.org/linux/man-pages/man2/tee.2.html 2019-04-26 17:55:47 +02:00
orbitcowboy 3ca2db062c wxwidgets.cfg: Added support for wxRect::Contains(). 2019-04-26 17:46:09 +02:00
orbitcowboy 322ef3ebb3 wxwidgets.cfg: Fixed wrong function name. 2019-04-26 17:43:19 +02:00
orbitcowboy 754e5f6529 wxwidgets.cfg: Added support for more interfaces. 2019-04-26 17:41:08 +02:00
orbitcowboy 7d0bb0dc29 posix.cfg: Improved validation of file descriptors. 2019-04-26 16:58:21 +02:00
orbitcowboy 2dd42b867f gnu.cfg: Added support for dup3(). Reference: http://man7.org/linux/man-pages/man2/dup2.2.html 2019-04-26 16:57:43 +02:00
orbitcowboy 2d7323c65f posix.cfg: Added support for sendfile(). 2019-04-26 16:47:49 +02:00
orbitcowboy c693e8969d gnu.cfg: Added support for more interfaces. 2019-04-26 16:39:04 +02:00
Sebastian 53357f2f31
boost.cfg: Add configuration for Boosts smart pointers (#1811) 2019-04-26 12:41:44 +02:00
Paul Fultz II c4325bbec3 Fix issue 9103: False positive duplicateConditionAssign (#1808)
* Fix issue 9103: False positive duplicateConditionAssign

* Update conditional message
2019-04-26 12:30:41 +02:00
Paul Fultz II e856920488 Fix false positive with ignoredReturnValue with std::move (#1809) 2019-04-26 12:22:31 +02:00
Daniel Marjamäki b1ca7c9a66 astyle formatting
[ci skip]
2019-04-26 11:30:35 +02:00
Paul Fultz II 39f4374446 Improve diagnostics with null smart pointers (#1805)
* Warn when dereferencing null smart pointers

* Improve tracking of smart pointer values

* Use library isSmartPointer
2019-04-26 11:30:09 +02:00
orbitcowboy bc7e835524 posix.cfg: Added support for ttyname_r(). 2019-04-26 10:24:10 +02:00
orbitcowboy 6d681a0959 posix.cfg: Issue a warning in case a function accepting a file descriptor is called with a negative value. 2019-04-26 10:16:29 +02:00
orbitcowboy f288e18c2c posix.cfg: Added support for more interfaces. 2019-04-26 09:48:38 +02:00
orbitcowboy 254cdd3b19 windows.cfg: Issue a warning in case _close() is called with a negative file descriptor. 2019-04-26 09:26:25 +02:00
orbitcowboy c0b533c452 gnu.cfg: Warn for socket/file-descriptors having negatives values. 2019-04-25 17:07:44 +02:00
orbitcowboy c4fb56e550 posix.cfg: Warn for socket/file-descriptors having negatives values. 2019-04-25 17:04:30 +02:00
orbitcowboy 4a91b7ec77 Merge branch 'master' of https://github.com/danmar/cppcheck 2019-04-25 16:58:47 +02:00