Commit Graph

9503 Commits

Author SHA1 Message Date
Sebastian 02c0240dcd
Fix #9322: bsd.cfg, gnu.cfg: Fix FP for mmap when argument "fd" is -1 (#2306)
In contrast to POSIX, GNU and BSD allow or even require the argument
"fd" to be set to -1 if MAP_ANONYMOUS or MAP_ANON is specified.
2019-10-30 09:39:50 +01:00
Daniel Marjamäki 210232d35c Fixed #9314 (false positive: (error) Uninitialized variable: ret) 2019-10-29 20:36:58 +01:00
Paul Fultz II 1ef85f9229 Fix issue 9432 and 9433: False positive: Reference to temporary returned (#2302) 2019-10-29 19:12:58 +01:00
Daniel Marjamäki 2c1905cc2b AST: Somewhat better handling of '{x}' function parameters 2019-10-27 12:00:08 +01:00
Daniel Marjamäki f03945a9e2 AST: better handling when returning list of lambdas 2019-10-26 19:19:20 +02:00
IOBYTE 6b4a3bc830 fix #9431 (Invalid syntax error on valid C++ code) (#2298) 2019-10-26 17:39:46 +02:00
Sebastian 8fb794e731
libsigc++.cfg: Add configuration for library libsigc++ (#2291)
* libsigc++.cfg: Add configuration for library libsigc++

Reference: https://libsigcplusplus.github.io/libsigcplusplus/

* Make code compatible with libsigc++-2.0 instead of 3.0

Since Version 3.0 C++14 is required which is not (fully) supported in
some older GCC versions.
2019-10-26 17:37:14 +02:00
Georgy Komarov 72f07c8a33 Add MISRA checks for rules 21.1 and 21.12 (#2284)
* Add MISRA 21.1 check

This also required add static field for functions in symboldatabase.

* Add MISRA R21.12

* Use newer ASSERT macroses in tests
2019-10-26 08:32:46 +02:00
Daniel Marjamäki 37bb19f02c Verify: Fix a false negative in the itc test suite 2019-10-25 21:46:02 +02:00
Wolfgang Stöggl 1ea3fc8083 Allow SSIZE_T in addition to ssize_t (#2263)
The Windows Data Type SSIZE_T is declared in BaseTsd.h
However, it is written in capital letters

- Fixes e.g. the following false positive:
  (portability) %zd in format string (no. 1) requires 'ssize_t' but the
  argument type is 'SSIZE_T {aka signed long long}'.
  [invalidPrintfArgType_sint]
2019-10-24 21:51:20 +02:00
Daniel Marjamäki fbd59b2fc5 Verify: Add test script itc.py. clarify juliet.py test script 2019-10-24 21:48:34 +02:00
Daniel Marjamäki dedee2b173 SymbolDatabase: Better ValueType handling for containers 2019-10-23 19:54:59 +02:00
Daniel Marjamäki e879de6489 Verify: Update Juliet Testing 2019-10-23 16:49:45 +02:00
Daniel Marjamäki 87f65230ae SymbolDatabase: Better valuetype handling of container addition 2019-10-23 12:42:46 +02:00
Daniel Marjamäki f131a99ae3 SymbolDatabase: Improved ValueType in range for loop 2019-10-23 11:52:29 +02:00
Daniel Marjamäki c5c07b61a6 SymbolDatabase: Fix type for expression 'x = uint8_t(a[b])' 2019-10-22 20:40:36 +02:00
Daniel Marjamäki cf1dd2e6f6 AST: Fix AST when returning list of lambda functions 2019-10-22 18:39:59 +02:00
orbitcowboy 24d6794ba6 windows.cfg: Added support for more interfaces. 2019-10-21 10:09:20 +02:00
versat 6cf0aed737 test/cfg/runtests.sh: Remove verbose output (meant for debugging) 2019-10-21 08:53:21 +02:00
Rikard Falkeborn 73a569be97 TestBufferOverRun: Handle string literals (#2287) 2019-10-21 07:11:22 +02:00
Rikard Falkeborn f83eb127ae ValueFlow: sizeof string and char literals (#2285) 2019-10-20 21:02:28 +02:00
Daniel Marjamäki 78c02f0505 ValueFlow: Fixed false positives after escape scope 2019-10-20 20:57:16 +02:00
Daniel Marjamäki 223ceeb97f SymbolDatabase: Do not set constructor flag for function in namespace 2019-10-20 18:12:52 +02:00
Daniel Marjamäki 82d8f3e7f5 SymbolDatabase: Fix crash if std::shared_ptr type is only forwarded, not defined 2019-10-20 17:00:15 +02:00
Daniel Marjamäki e50b9e2bef Fixed #8784 (False positive uninitialized variable) 2019-10-20 15:20:05 +02:00
Daniel Marjamäki 68ea60d207 Try to make Travis happy 2019-10-20 07:44:56 +02:00
Rikard Falkeborn 5c061c1c12 Set correct type and size of string and char literals (#2275)
* Set correct type and size of string and char literals

Use that string and char literal tokens store the prefix. This makes
it possible to distinghuish between different type of string literals
(i.e., utf8 encoded strings, utf16, wide strings, etc) which have
different type.

When the tokens holding the string and character values have the correct
type, it is possible to improve Token::getStrSize() to give the correct
result for all string types. Previously, it would return the number of
characters in the string, i.e., it would give the wrong size unless
the type of the string was char*.

Since strings now can have different size (in number of bytes) and
length (in number of elements), add a new helper function that returns
the number of characters. Checkers have been updated to use the correct
functions.

Having the size makes it possible to find more problems with prefixed
strings, and to reduce false positives, for example in the buffer
overflow checker.

Also, improve the stringLiteralWrite error message to also print the
prefix of the string (if there is one).

* Add comment and update string length
2019-10-20 07:11:57 +02:00
Daniel Marjamäki 00fae7fb42 Fixed #9261 (Inconsistent violation report between using global enum and namespaced enum.) 2019-10-20 07:07:38 +02:00
Daniel Marjamäki 4943771e41 Fix #9262 (False positive on variable assignment when putting enum in namespace) 2019-10-19 21:41:50 +02:00
Daniel Marjamäki 9a2b71494f ValueFlow: Set value for :: 2019-10-19 21:08:59 +02:00
IOBYTE 5658dfcaf3 better fix for #9392 that also handles namespaces (#2282) 2019-10-18 18:05:48 +02:00
Daniel Marjamäki e0093c99ce Fixed #9276 (False positive: ValueFlow does not handle return in switch properly.) 2019-10-18 16:16:56 +02:00
versat 094caf31ac std.cfg: Remove redundant configurations for vector::(push|pop)_back()
Add tests in std.cpp to verify that a configuration for the functions
exists.
2019-10-18 12:40:10 +02:00
Sebastian 8eea046e5b
std.cfg: Add support for std::fill_n() (#2273)
Reference: https://en.cppreference.com/w/cpp/algorithm/fill_n
2019-10-18 12:24:57 +02:00
Daniel Marjamäki 3a0a0fdefb Fixed #9424 (False positive: known condition after function call) 2019-10-18 08:21:07 +02:00
Sebastian 478625c802
kde.cfg: Add KDE configuration and tests (#2278)
Reference: https://kde.org
2019-10-17 21:29:32 +02:00
Daniel Marjamäki 99ef64459b Fixed #9344 (FP redundantAssignment related to increasing index variable for vector) 2019-10-17 18:31:05 +02:00
orbitcowboy 7c48874793 #9347: Added a robustness test for scanf 2019-10-17 17:50:26 +02:00
Daniel Marjamäki 15d7b9c83f Fixed #9347 (FP uninitvar for pointer passed to sscanf) 2019-10-17 17:41:54 +02:00
IOBYTE e4d2e9d2af Fix #9421 (syntaxError on incomplete code (from z3)) (#2274) 2019-10-16 20:56:53 +02:00
Ken-Patrick Lehrmann 24211cf8b9 Fix crashes in valueflow (#2236)
* Fix crashes in valueflow

http://cppcheck1.osuosl.org:8000/crash.html

For instance in http://cppcheck1.osuosl.org:8000/styx
```
==19651==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000001c (pc 0x556f21abc3df bp 0x7ffc140d2720 sp 0x7ffc140d2710 T0)
==19651==The signal is caused by a READ memory access.
==19651==Hint: address points to the zero page.
    #0 0x556f21abc3de in Variable::isGlobal() const ../lib/symboldatabase.h:342
    #1 0x556f221f801a in valueFlowForwardVariable ../lib/valueflow.cpp:2471
    #2 0x556f22208130 in valueFlowForward ../lib/valueflow.cpp:3204
    #3 0x556f221e9e14 in valueFlowReverse ../lib/valueflow.cpp:1892
    #4 0x556f221f1a43 in valueFlowBeforeCondition ../lib/valueflow.cpp:2200
    #5 0x556f2223dbb5 in ValueFlow::setValues(TokenList*, SymbolDatabase*, ErrorLogger*, Settings const*) ../lib/valueflow.cpp:6521
    #6 0x556f220e5991 in Tokenizer::simplifyTokens1(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../lib/tokenize.cpp:2342
    #7 0x556f21d8d066 in CppCheck::checkFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::istream&) ../lib/cppcheck.cpp:508
    #8 0x556f21d84cd3 in CppCheck::check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../lib/cppcheck.cpp:192
    #9 0x556f21a28796 in CppCheckExecutor::check_internal(CppCheck&, int, char const* const*) ../cli/cppcheckexecutor.cpp:884
    #10 0x556f21a24be8 in CppCheckExecutor::check(int, char const* const*) ../cli/cppcheckexecutor.cpp:198
    #11 0x556f22313063 in main ../cli/main.cpp:95
```

* Add test case for crash in valueflow
2019-10-16 20:54:07 +02:00
Rikard Falkeborn 297360920a Keep prefix in string and char literals (#2272)
Keeping the prefix in the token allows cppcheck to print the correct
string and char literals in debug and error messages.

To achieve this, move some of the helper functions from token.cpp to
utils.h so that checks that look at string and char literals can reuse
them. This is a large part of this commit.

Note that the only user visible change is that when string and char
literals are printed in error messages, the prefix is now included.

For example:

	int f() {
		return test.substr( 0 , 4 ) == U"Hello" ? 0 : 1 ;
	};

now prints U"Hello" instead of "Hello" in the error message.
2019-10-16 11:41:33 +02:00
Daniel Marjamäki 7d6d561c84 SymbolDatabase: Better handling of function call using smart pointer 2019-10-15 19:33:25 +02:00
Sebastian e3fe559f0d
windows.cfg: Add support for `__alignof()` (#2271)
Reference:
https://docs.microsoft.com/en-us/cpp/cpp/alignof-operator?view=vs-2019
2019-10-15 16:02:28 +02:00
Daniel Marjamäki 4a4b4963cc SymbolDatabase: Fix function lookup for '::func()' 2019-10-15 12:39:02 +02:00
Sebastian 60de5e12dd gnu.cfg: Add configuration for __alignof__() (#2268)
Reference: https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Alignment.html
2019-10-14 20:59:38 +02:00
Daniel Marjamäki 62d972061b astyle formatting
[ci skip]
2019-10-14 19:41:51 +02:00
Daniel Marjamäki 8c5c070d6a ExprEngine: Improved handling of struct member assignments in loop 2019-10-14 19:41:32 +02:00
Sebastian 0527b80174
gnu.cfg: Add support for __glibc_likely() and __glibc_unlikely() (#2267)
Reference:
https://sourceware.org/glibc/wiki/Style_and_Conventions#Branch_Prediction
2019-10-14 12:16:28 +02:00
Daniel Marjamäki bf61bcf402 ValueType: Set ValueType for constructor calls 2019-10-14 09:19:16 +02:00