Commit Graph

21434 Commits

Author SHA1 Message Date
Rikard Falkeborn df800e35d4 Fix memleak FP with return with parenthesis (#2202)
* Fix memleak FP with return  with parenthesis

Fix FPs pointed out by daca@home on the following form:

    void* f(void) {
        void* x = malloc(1);
        return(x);
    }

Fix it by only skipping tokens if there is an actual match with a
variable. This allows to remove the special casing of "return;".

* Add testcase with cast
2019-09-22 19:18:31 +02:00
Daniel Marjamäki 6e17853ea9 ExprEngine: Guess function call return value 2019-09-22 16:40:48 +02:00
Daniel Marjamäki 5c07cfd2e8 ExprEngine: Better handling of pointer aliasing 2019-09-22 15:58:55 +02:00
Daniel Marjamäki ec4b7c1f4b ExprEngine: Better handling of pointers 2019-09-22 10:56:57 +02:00
amai2012 6c9839a585 Validate rules files 2019-09-21 21:42:13 +02:00
Daniel Marjamäki 7d6fd915be ExprEngine: Better handling of compound assignments 2019-09-21 21:15:51 +02:00
Wolfgang Stöggl 52aab1e80c Fix xml syntax in token-matching.xml (#2197)
The file token-matching.xml contains multiple rules
- Add <rules></rules> xml tags
- Fixes the following xmllint error:
  ./rules/token-matching.xml:10: parser error :
  Extra content at the end of the document
  <rule version="1">
  ^
2019-09-21 20:41:45 +02:00
amai2012 16f1d8196b Add validateRules target (xmllint) for rules/*.xml 2019-09-21 20:33:48 +02:00
Paul Fultz II c1961cec1c Fix issue 9362: FP: (style) Condition '(v&1)==0' is always false (#2200) 2019-09-21 19:53:54 +02:00
Daniel Marjamäki da91c139d5 ExprEngine: Passing array to function, array data might be overwritten 2019-09-21 19:34:06 +02:00
orbitcowboy 962e7c790b windows.cfg: Added support for macros from minwinbase.h 2019-09-21 15:08:51 +02:00
Rikard Falkeborn 46ac0d79c1 Checkmemleakautovar: fix crash and FP (#2196)
This fixes crashes found by daca where valueType() is NULL. Also,
somewhat related, it removes warnings when casting to a type that is
unknown to cppcheck, for example, there is no longer a warning for the
following code:

	void* f() {
		void *x = malloc(1);
		return (mytype)x;
	}
2019-09-21 14:59:54 +02:00
orbitcowboy 5ac0b0e752 qt.cfg: Added support for more macros, found by daca@home. 2019-09-21 14:42:37 +02:00
orbitcowboy f18cf354bd qt.cfg: Added support for Q_DECLARE_INTERFACE()-macro, found by daca@home. 2019-09-21 14:39:14 +02:00
Daniel Marjamäki b2cab003ff ExprEngine: Fix output for arrays 2019-09-21 14:17:16 +02:00
orbitcowboy 860339d8b4 wxwidgets.cfg: Added support deprecated EVT_GRID_CELL_CHANGE()-event macro. 2019-09-21 13:19:04 +02:00
Daniel Marjamäki 3d0d3ec4c5 ExprEngine: handling array initialization with string literal 2019-09-21 11:36:34 +02:00
Tyson Nottingham d6a70d27c7 Fix false negatives in checkAssignBoolToFloat and minor related improvements (#2198)
* Fix false negatives in checkAssignBoolToFloat

Detect assignments to expressions involving pointer dereferences, array
element accesses, etc.

* Pass assignment token to assignBoolToFloatError

Pass assignment token rather than boolean token to make error reporting
consistent between checkAssignBoolToFloat and checkAssignBoolToPointer,
as well as with other assignment checks in the code base.

* Make checkAssignBoolToPointer check consistent with checkAssignBoolToFloat
2019-09-21 08:24:54 +02:00
Paul Fultz II 40f1635c35 Fix issue 9361: false positive: (style) Condition 'isdigit(c)!=0' is always true (#2199) 2019-09-21 08:19:54 +02:00
Oliver Stöneberg 65d1e90aa3 deleted methods should be public (#2193) 2019-09-20 21:58:09 +02:00
Oliver Stöneberg b5c598cca4 added missing OVERRIDE usage and removed redundant virtual (#2190) 2019-09-20 21:57:16 +02:00
Oliver Stöneberg 9028b4a81d do not access static methods through instance (#2189) 2019-09-20 21:54:30 +02:00
Ken-Patrick Lehrmann 49b7ef84d9 Fix crashes in checkleakautovar (#2195)
Crashes found by daca@home
http://cppcheck1.osuosl.org:8000/crash.html

For instance
```
2019-09-20 16:27
ftp://ftp.se.debian.org/debian/pool/main/n/nedit/nedit_5.7.orig.tar.gz
cppcheck-options: -j1 --library=posix --library=gnu --library=motif -D__GNUC__ --check-library --inconclusive --enable=style,information --platform=unix64 --template=daca2 -rp=temp temp
platform: Linux-4.19.0-6-amd64-x86_64-with-debian-10.1
python: 2.7.16
client-version: 1.1.37
cppcheck: head 1.89
head-info: 38dec6a9a (2019-09-20 16:46:57 +0200)
count: Crash! 934
elapsed-time: -11.0 9.0
head results:
Checking temp/nedit-5.7/source/shell.c: __GNUC__=1...

Program received signal SIGSEGV, Segmentation fault.
0x000055555564b862 in CheckLeakAutoVar::ret (this=0x7fffffffb8c0, tok=0x5555582ea9e0, varInfo=...) at lib/token.h:340
340	        return mImpl->mValueType;
 #0  0x000055555564b862 in CheckLeakAutoVar::ret (this=0x7fffffffb8c0, tok=0x5555582ea9e0, varInfo=...) at lib/token.h:340
 #1  0x0000555555651764 in CheckLeakAutoVar::check (this=0x7fffffffb8c0) at build/checkleakautovar.cpp:714
 #2  0x0000555555652b37 in CheckLeakAutoVar::runChecks (this=<optimized out>, tokenizer=0x7fffffffc3a0, settings=<optimized out>, errorLogger=<optimized out>) at lib/checkleakautovar.h:108
 #3  0x00005555556bc833 in CppCheck::checkNormalTokens (this=0x7fffffffce50, tokenizer=...) at build/cppcheck.cpp:732
 #4  0x00005555556bf694 in CppCheck::checkFile (this=0x7fffffffce50, filename=..., cfgname=..., fileStream=...) at build/cppcheck.cpp:542
 #5  0x00005555556c1cb8 in CppCheck::check (this=this@entry=0x7fffffffce50, path="temp/nedit-5.7/source/shell.c") at /usr/include/c++/8/bits/basic_string.h:936
 #6  0x00005555557fd63f in CppCheckExecutor::check_internal (this=0x7fffffffdbd0, cppcheck=..., argv=<optimized out>) at cli/cppcheckexecutor.cpp:884
 #7  0x00005555557fda92 in CppCheckExecutor::check (this=this@entry=0x7fffffffdbd0, argc=argc@entry=14, argv=argv@entry=0x7fffffffdf58) at cli/cppcheckexecutor.cpp:198
 #8  0x00005555555e6358 in main (argc=14, argv=0x7fffffffdf58) at cli/main.cpp:95

DONE
```
2019-09-20 21:29:17 +02:00
Daniel Marjamäki 6c59957109 ExprEngine: Better handling of conditions 2019-09-20 21:27:51 +02:00
Masafumi Koba 38dec6a9ac Add missing ending tag in XML example (#2187) 2019-09-20 16:46:57 +02:00
versat 02953b791c googletest.cfg: Add some GTEST_* macros 2019-09-20 16:07:42 +02:00
versat 88a034e4f1 gtk.cfg: Add some GTK_*() macros and the pod-type "GType" 2019-09-20 15:38:07 +02:00
Rikard Falkeborn 007b5d3e8d Fix #9343 (memleak FP when return with cast) (#2162)
This was most likely introduced when the checks were changed to run on
the full tokenlist instead of the simplified one.

Take care to warn about cases where casts destroy the pointer, such as

	uint8_t f() {
		void* x = malloc(1);
		return (uint8_t)x;
	}
2019-09-20 15:09:27 +02:00
Daniel Marjamäki 049f6475ee astyle formatting
[ci skip]
2019-09-20 15:07:27 +02:00
Paul Fultz II ad8abdb0c3 Add impossible values to ValueFlow (#2186)
* Add impossible category

* Replace values

* Try to adjust known values

* Add ! for impossible values

* Add impossible with possible values

* Remove contradictions

* Add values when the branch is not dead

* Only copy possible values

* Dont bail on while loops

* Load std lib in valueflow

* Check for function calls

* Fix stl errors

* Fix incorrect impossible check

* Fix heap-after-use error

* Remove impossible values when they are lowered

* Show the bound and remove overlaps

* Infer conditions

* Dont push pointer values through dynamic_cast

* Add test for dynamic_cast issue

* Add shifttoomanybits test

* Add test for div by zero

* Add a test for issue 9315

* Dont make impossible value inconclusive

* Fix FP with shift operator

* Improve handleKnownValuesInLoop for impossible values

* Fix cppcheck warning

* Fix impossible values for ctu

* Bailout for streams

* Check equality conditions

* Fix overflows

* Add regression test for 9332

* Remove duplicate conditions

* Skip impossible values for invalid value

* Check for null

* Rename bound to range

* Formatting
2019-09-20 15:06:37 +02:00
versat dc1cdd2b76 addons/test/test-*.py: Improve documentation about running the tests 2019-09-20 13:39:38 +02:00
IOBYTE 8c5cf8c029 Fixed #9046 syntaxError (#2180)
* Fixed #9046 syntaxError

* fix another syntax error

* fix some more syntax errors
2019-09-20 12:35:01 +02:00
Daniel Marjamäki 8fba2af267 Try to make Travis happy 2019-09-20 07:04:58 +02:00
Daniel Marjamäki 6c38b69e11 Rename dataIndex to mDataIndex according to our naming conventions 2019-09-20 06:12:35 +02:00
Sebastian 7d26a694da
.travis.yml: Run addon tests also with Python 3 (#2185)
Python 3 does not search parent directories of the initially executed
script for modules imported by modules in this parent directory by
default. So simply set the PYTHONPATH to the ./addons directory. Thus
all scripts are found. It is similar to running the test-*.py script
from the ./addons directory, but this way all the paths in the test-*.py
scripts do not have to be changed (for example to find the cppcheck
executable.
For more details regarding the parent directory issue see for example:
https://stackoverflow.com/questions/11393492/python-package-import-from-parent-directory
For details about the used PYTHONPATH solution see:
https://stackoverflow.com/questions/4580101/python-add-pythonpath-during-command-line-module-run
2019-09-19 20:46:16 +02:00
Oliver Stöneberg de9f489b08 use range loops / constness (#2181)
* use range loops / constness

* platform.cpp: avoid shadowed variable
2019-09-19 20:29:33 +02:00
Daniel Marjamäki 5f0f8afc27 ExprEngine: Print some 'debug' output 2019-09-19 20:18:55 +02:00
Sebastian bf55e835aa
Windows testrunner: Add testexprengine.cpp (#2184)
Add export of executeAllFunctions() in exprengine.h
2019-09-19 19:40:00 +02:00
versat 28e3e01ff8 lua.cfg: Add some functions/macros, partly found by daca@home 2019-09-19 16:27:37 +02:00
orbitcowboy 06ba93b84a qt.cfg: Added support fore Q_OVERRIDE-macro. 2019-09-19 15:22:36 +02:00
orbitcowboy 1855a44b3b microsoft_atl: Added support fore macros. 2019-09-19 13:09:40 +02:00
versat 7277fe5a2b gnu.cfg: Add support for macro __extension__
The macro does nothing except preventing from warnings when compiling
with "pedantic" or other options.
2019-09-19 12:27:21 +02:00
Sebastian 174badf242
python.cfg: Improve Python C API configuration (#2183)
Add configurations for functions reported by daca@home.
Remove redundantly configured functions.
Add/improve some other function configurations.
2019-09-19 10:34:14 +02:00
Rikard Falkeborn 518bb5195c dmake: Sort header dependencies (#2182)
Makes it simpler to check diffs, and prevents updates to Makefile due to
changes in header includes.
2019-09-19 09:26:59 +02:00
Daniel Marjamäki 745c91106e Removed unused Data::dump 2019-09-19 09:16:18 +02:00
Sebastian 8207fb7b14
cairo.cfg: Add library configuration/tests/... for cairo library (#2176)
Reference: https://www.cairographics.org/
2019-09-19 08:48:04 +02:00
orbitcowboy 3d3f62aefd windows.cfg: Added support for more interfaces. 2019-09-19 08:34:03 +02:00
orbitcowboy f6d3bb8cc8 windows.cfg: Added support for more interfaces and constants. 2019-09-19 08:29:45 +02:00
orbitcowboy b37b0c0f78 Running astyle [ci skip] 2019-09-19 08:03:29 +02:00
orbitcowboy f5d874955c wxwidgets.cfg: Added support for more interfaces. 2019-09-19 08:03:12 +02:00