Commit Graph

8395 Commits

Author SHA1 Message Date
Paul Fultz II ed197f235a Fix issue 4693: Diagnostic when using the same iterators to an algorithm (#1326)
* Fix issue 4693: Diagnostic when using the same iterators to an algorithm

* Update classinfo
2018-08-05 09:10:54 +02:00
rikardfalkeborn 710d7ce015 Add checks of log2 and log1p range (#1324)
* Add tests for log10{,f,l} valid arguments

* Add log2{,f,l} to checkfunctions

* Add log1p{,f,l} to checkfunctions

* checkfunctions: Simplify check for log function limit out of range

The conditions for negative and non-negative int and float were
identical so the call to isNegative can be removed and the if-statements
be simplified.
2018-08-03 12:14:39 +02:00
Paul Fultz II 0d35a96594 Improve checking of mismatch iterators (#1293) 2018-07-26 22:00:48 +02:00
Daniel Marjamäki 54e2726bf3 Fixed #8636 (Misleading verbose message if virtual method called from destructor) 2018-07-26 09:16:17 +02:00
Daniel Marjamäki fc5d8e5082 TestSuite: Allow that verbose messages are reported in a test 2018-07-26 09:15:33 +02:00
Daniel Marjamäki c666f74755 astyle formatting
[ci skip]
2018-07-25 23:02:16 +02:00
Paul Fultz II f093692551 ValueFlow: Set values in else branch even when the first branch modifies the value (#1309)
* Set values in else branch even when the first branch modifies the value

* Move tests

* Add check for goto

* Remvoe todo

* Also check scope is noreturn

* Use isEscapeScope when variables are changed
2018-07-25 22:59:54 +02:00
Daniel Marjamäki f9a5a114bb astyle formatting
[ci skip]
2018-07-25 07:44:06 +02:00
Paul Fultz II 9895ea5ff2 Fix issue 470: Condition is always true or false on logical operators (#1294)
* Fix issue 470: Condition is always true or false on logical operators

* Dont warn on literals

* Compute logical operators using valueflow

* Fix FP when using literals

* Always warn on subconditions that are always true

* Use percent matches first

* Add test for logical operators

* Check if parent is null
2018-07-23 08:51:59 +02:00
lordylike 12e58c8521 fix ticket 8570: passedByValue with member initializer list and std::move (#1316)
* fix ticket 8570

allow member initializer list variables that are moved to be non-const

* review feedback

* replace tabs with spaces in test code
2018-07-22 15:01:18 +02:00
Daniel Marjamäki 77b653bf94 Clarify warnings when char literals are converted to bool in conditions 2018-07-21 18:40:06 +02:00
Sebastian f862cf603f
posix.cfg: Add some pthread_mutex_* functions. (#1320)
References:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
2018-07-21 17:52:12 +02:00
rikardfalkeborn 30a8d953e3 Move sqrt{,f,l} argument checks to cfg file (#1313) 2018-07-20 20:56:39 +02:00
Sebastian 4ef452132c
posix.cfg,gnu.cfg: Add (get|set)hostname functions. (#1315)
Reference for POSIX gethostname:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html
Reference for sethostname:
http://man7.org/linux/man-pages/man2/gethostname.2.html
2018-07-18 09:40:06 +02:00
Daniel Marjamäki 7c4820e047 Rename Library::isargvalid() 2018-07-15 23:05:48 +02:00
rikardfalkeborn 491ee577c6 Support floats in valid config (#1297)
* Add tests for invalid ranges

* Refactor loadLibErrors

This reduces the amount of code slightly and will simplify adding
more tests.

* Handle empty valid field

Before this change, the sequence <valid></valid> in a config file would
result in a segmentation fault. Now an empty field results in the error
message:

cppcheck: Failed to load library configuration file 'mycfg.cfg'. Bad attribute value '""'

* Add support for valid for floating point arguments

Previously, it was not possible to add valid ranges to floating point
arguments since it only handled integers. This made ranges not work well
for floating point arguments since arguments were cast to integers
before the ranges were handled.

Fix this by using doubles instead of integers if the argument is a float.
Add some tests for this and make sure errors are printed with enough
precision (somewhat arbitrarily chosen).

Note that it is still only possible to add integer ranges (i.e. -1:1).

* Add support for floats in configuration valid range

Now that it is possible to handle decimal arguments, there is no reason
to not allow non-integer ranges. Take care to not allow broken
configurations.

* Move check to within if-clause

* Move asin{,f,l} and acos{,f,l} input checks to config file
2018-07-15 22:47:56 +02:00
rikardfalkeborn 0e639ea7c9 runtest.sh: Bugfix cfg dir when run in test/cfg (#1311)
Commit 5cc8da2db4 introduced syntax checking of xml-files. This broke
running the file directly in the test/cfg folder since it assumed the
config files to check were located in cfg in the current working
directory. Fix this by adding a variable that holds the correct path.
2018-07-15 22:24:31 +02:00
Paul Fultz II 5d1fdf7958 Fix issue 7904: Handle double nots in isSameExpression (#1305)
* Fix issue 7904: Handle double nots in isSameExpression

* Skip checking double nots in assignments

* Use ast to check for double not
2018-07-15 11:30:02 +02:00
Paul Fultz II 42f075c3fa Skip literals for always true/false (#1304) 2018-07-12 23:06:47 +02:00
Sebastian 5cc8da2db4
cfg/runtests.sh: Check syntax of defines in configuration files. (#1303)
travis: Add xmlstarlet package used by cfg/runtests.sh
2018-07-12 08:40:26 +02:00
Daniel Marjamäki b398398dec Fixed #8360 (false positive "Ineffective call of function 'empty()'") 2018-07-10 22:58:02 +02:00
Daniel Marjamäki 7e2858f158 astyle formatting
[ci skip]
2018-07-10 22:56:18 +02:00
Daniel Marjamäki 03faa25d12 Conditions: Better handling of function calls 2018-07-08 15:58:04 +02:00
amai2012 c2f0828a61 #6645 false negative: condition is always false. Add a regression test 2018-07-03 08:25:37 +02:00
Daniel Marjamäki 24dd4c9c26 Restore code in checkVariableScope. Fixes false negative 2018-07-01 22:31:45 +02:00
Daniel Marjamäki 60ac463a79 CheckClass: Restore a few warnings about member initialization of classes 2018-06-29 22:54:12 +02:00
Alexander Mai 320a957bbc Extend TestSymbolDatabase::findFunction19 to outline different results depending whether char is signed or unsigned on compile time 2018-06-28 22:16:18 +02:00
Daniel Marjamäki 61c56eda44 Tweak the CheckClass::constructors() check 2018-06-27 14:02:57 +02:00
Daniel Marjamäki 10e693a8c3 Revert "SymbolDatabase: Improved lookup of function calls"
This reverts commit 3c87d60d5d.
2018-06-26 23:14:12 +02:00
Daniel Marjamäki 3c87d60d5d SymbolDatabase: Improved lookup of function calls 2018-06-26 22:12:12 +02:00
Daniel Marjamäki c583fb9186 Revert "SymbolDatabase: Improved lookup of function calls"
This reverts commit e4a70f87e6.
2018-06-26 13:05:33 +02:00
Daniel Marjamäki e4a70f87e6 SymbolDatabase: Improved lookup of function calls 2018-06-26 11:38:45 +02:00
Daniel Marjamäki 33493883b2 TestSymbolDatabase: Remove unused variable 2018-06-24 17:13:27 +02:00
Daniel Marjamäki ea6a9c965d TestSymbolDatabase: Code cleanup 2018-06-24 17:06:51 +02:00
Daniel Marjamäki cde63c7573 Use Variable::valueType instead of Variable::typeStartToken in auto variables 2018-06-24 08:25:19 +02:00
Daniel Marjamäki 655a8b21b6 Fix false positive 'passedByValue' when address of argument is used 2018-06-23 23:25:06 +02:00
Daniel Marjamäki 2a8296879c CheckOther: Use Variable::valueType() instead of Variable::typeStartToken 2018-06-23 16:42:36 +02:00
Daniel Marjamäki d0614b9b36 varScope: Fix false negatives for references 2018-06-22 22:51:03 +02:00
Daniel Marjamäki 10fc070f44 SymbolDatabase: Better handling of type aliases in ValueType 2018-06-20 14:49:55 +02:00
Daniel Marjamäki b4cb2505c3 SymbolDatabase: Add Variable::valueType(). First step to reuse ValueType handling in Variable 2018-06-20 10:00:15 +02:00
Daniel Marjamäki 610b26bfbc Rename private member _platform_types 2018-06-17 16:58:28 +02:00
Daniel Marjamäki 074177fc6e Rename private member variables 2018-06-17 16:55:02 +02:00
Daniel Marjamäki e08859e329 Fix testrunner compiling 2018-06-16 22:28:14 +02:00
Daniel Marjamäki 76280fe847 Fix testrunner 2018-06-16 21:36:30 +02:00
Daniel Marjamäki 593f7eee38 Fixed #8624 (Crash below CheckOther::checkDuplicateExpression) 2018-06-14 22:39:26 +02:00
Daniel Marjamäki 45379a3aa6 Updated copyright year for modified files
[ci skip]
2018-06-10 22:07:21 +02:00
Paul Fultz II daacf27c2e Fix false positive from issue 8612 (#1285) 2018-06-10 00:05:23 +02:00
Daniel Marjamäki 03b2e0eee7 inline suppressions: treat arithmetic operators as start-of-comment 2018-06-09 22:50:51 +02:00
Paul Fultz II 8d53bcfd63 Fix FP when using non-const members and also check return type of function (#1283) 2018-06-09 08:05:19 +02:00
orbitcowboy d10788164a windows.cfg: Added support for _locale_t 2018-06-08 14:41:56 +02:00
orbitcowboy c56033f998 test/windows.cfg: Fixed wrong test case. 2018-06-08 14:33:37 +02:00
Daniel Marjamäki 84f0a18053 passedByReference: avoid false positives for std::pair 2018-06-08 10:19:02 +02:00
Daniel Marjamäki 44c78d1770 passedByReference: avoid false positives for std::function 2018-06-08 08:40:14 +02:00
Daniel Marjamäki de09c117bf Fixed #8618 (False positive: shared_ptr is passed by reference by intention) 2018-06-07 22:39:21 +02:00
Daniel Marjamäki 1abc9008d8 Fixed #8573 (FP noCopyConstructor - derive from noncopyable class) 2018-06-06 16:02:25 +02:00
Daniel Marjamäki b9c1308a81 Fixed #8575 (false positive: longCastAssign) 2018-06-04 22:51:21 +02:00
orbitcowboy 74b18d7fd9 windows.cfg: Added support for _strncpy_s_l(). 2018-06-04 16:58:09 +02:00
Daniel Marjamäki 7b106c067a Fixed #8603 (SymbolDatabase: 2 scopes with same function) 2018-06-03 23:14:24 +02:00
orbitcowboy 55ff7c0823 test std.cfg: Updated tests for strncpy_s(). 2018-05-31 11:23:54 +02:00
Daniel Marjamäki ccbfd623d5 astyle formatting
[ci skip]
2018-05-31 07:02:08 +02:00
amai2012 8d55d361ae #8602 Template default parameter without name yields syntax error 2018-05-30 17:09:31 +02:00
orbitcowboy c7993c38b5 bsd.cfg: Added support for strlcat(). 2018-05-30 16:47:00 +02:00
orbitcowboy d412c3908f test std.cfg: Fixed introduced regression. 2018-05-30 16:30:00 +02:00
orbitcowboy 39feb150c0 std.cfg and windows.cfg: Added support for wcscat_s() and _tcscat_s(). 2018-05-30 16:25:09 +02:00
orbitcowboy ef82477d11 std.cfg: Do not take the return value of std::locale::global() into account. 2018-05-30 16:04:40 +02:00
IOBYTE 7681bbf227 Fixed #8146 (false positive: enum initialized using class member initializer syntax in struct in struct) (#1270) 2018-05-30 15:40:16 +02:00
orbitcowboy d06eb3eb8f std.cfg: Added support for strcat_s() (since C11). 2018-05-30 14:30:26 +02:00
IOBYTE 3982c81394 Add support for C++ attribute nodiscard for functions. (#1269) 2018-05-29 21:43:56 +02:00
Daniel Marjamäki 7d4a80fbd2 astyle formatting
[ci skip]
2018-05-29 16:30:33 +02:00
orbitcowboy 976e9e2544 Cleared -Wshadow warnings. 2018-05-29 11:54:07 +02:00
orbitcowboy 53c53db312 windows.cfg: Added support for _mbscat_s(). 2018-05-28 21:52:44 +02:00
orbitcowboy 75e28e46c5 windows.cfg: Added support for _mbscat(). 2018-05-28 10:08:11 +02:00
IOBYTE 36f7585798 Fixed #8600 (false-positive/regression: confusion between copy constructors of internal classes and lack of explicit keyword) (#1266) 2018-05-27 10:53:34 +02:00
orbitcowboy 5b6e6db376 test std.cfg: Added more test cases for strcat() functions. 2018-05-27 10:16:02 +02:00
orbitcowboy 3407f3e932 windows.cfg: Added test cases for CreateThread(). 2018-05-25 11:50:12 +02:00
orbitcowboy d7c8c46c10 test std.cfg: Improved testing for strcat() and wcscat(). 2018-05-25 08:36:47 +02:00
rebnridgway 42a65c5160 Fix crash bug #8579 (#1238)
* Added declaration for deletePrevious function

* Added definition for deletePrevious function

* Fixed crash from deleteThis invalidating pointers

The crash was caused by deleteThis() invalidating the pointer to a constant variable usage.  This happened when a usage followed an assignment.  This fixes bug #8579.

* Added tokensFront to match tokensBack

This means deletePrevious can set the list's front if necessary.

* Initialised tokensFront in appropriate places

* Switched to using default Token constructor

* Switched to using Token default constructor

* Switched to using default constructor for Token

* Added missing argument to Token constructor

* Changed to use default constructor for Tokens

* Switched to using default constructor for Tokens

* Switched to using default constructor for Token

* Added new test for deleting front Token

Also made sure to use the correct constructor for Token in other tests.

* Syntax error

* Replaced tokensFront and tokensBack with a struct

This decreases the size of the Token class for performance purposes.

* Replaced tokensFront and tokensBack with a struct

* Added tokensFrontBack to destructor

* Reworked to use TokensBackFront struct

Also ran astyle.

* Reworked to use TokenList's TokensFrontBack member

* Reworked to use TokensFrontBack struct

* Reworked to use TokensFrontBack struct

* Reworked to work with TokensFrontBack struct

* Removed unnecessary scope operator

* Added missing parentheses

* Fixed syntax error

* Removed unnecessary constructor

* Default constructor now 0-initialises everything

This is safer for not using a temporary TokensFrontBack object, and doesn't use delegating constructors which aren't supported yet.

* Fixed unsafe null check

* Added missing explicit keyword

* Fixing stylistic nits

Removed default constructor as it has been superseded by the single-argument constructor with a default argument value.
Renamed listEnds to tokensFrontBack.
Fixed if statement that was supposed to be adding safety but would actually cause a crash if tokensFrontBack was null.

* Fixing stylistic nits

Removed default constructor and replaced it with a single-argument constructor with a default value.

* Fixing stylistic nits

Renamed _listEnds to _tokensFrontBack.

* Fixing stylistic nits

Renamed _listEnds to _tokensFrontBack.
2018-05-25 07:15:05 +02:00
Sebastian 8b94bfaf0a
windows.cfg: Add macros SUCCEEDED() and FAILED(). (#1264)
Somehow the opposite inner condition is not detected when macros are used. I created this ticket: https://trac.cppcheck.net/ticket/8596
2018-05-24 14:52:32 +02:00
orbitcowboy 3311307227 windows.cfg: Added test cases for toupper/tolower functions. 2018-05-24 10:05:56 +02:00
IOBYTE fc1d62fd45 Fixed #7406 (Tokenizer::simplifyTypedef: array typedef used as template parameter) (#1257) 2018-05-22 17:31:58 +02:00
umanamente a3b02d6ece Fixed #8262: false positive memleak (`shared_ptr` in function argument) (#1249)
* Fixed #8262.
checkleakautovar.cpp:
* added `isFunctionCall` (supports template functions)
* smart pointer check in `functionCall`
* updated test case

* Renamed "bracket" to "parenthesis"

* (#8262) Fixed broken test

* (#8262) Code review comments

* (#8262) Renamed `tokOpeningBr` to `tokOpeningPar`
2018-05-22 09:08:23 +02:00
IOBYTE 8320be203d Fixed #8258 (Incorrect diagnostics when using delegating consturctor with default values) (#1255) 2018-05-22 06:42:37 +02:00
IOBYTE 5c15cd3981 Fix DACA2 SymbolDatabase bailout; unhandled code for final class (#1253)
* Fix DACA2 SymbolDatabase bailout; unhandled code for final class

* Replace Match with simpleMatch
2018-05-21 21:23:21 +02:00
Paul Fultz II 406aa6cf1c Improve support of using a lambda as a deleter (#1246)
* Improve support of using a lambda as a deleter

* Use simple match
2018-05-21 08:22:18 +02:00
IOBYTE 42ed5a6b98 Fixed #8581 (Delegating contructor warns for unintialized variables) (#1250)
* Fixed #8581 (Delegating contructor warns for unintialized variables)

* Replace Token::Match with isStandardType
2018-05-20 22:58:05 +02:00
Sebastian aa3722feea
windows.cfg: Add lstrlen() configuration and tests. (#1239)
Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ms647492(v=vs.85).aspx
2018-05-17 15:43:01 +02:00
orbitcowboy 3ad8fa5288 windows.cfg: Improved support for more types. 2018-05-16 16:26:40 +02:00
IOBYTE d567b878ba Fix template instantialion failure for qualified template type. (#1237) 2018-05-16 15:24:23 +02:00
orbitcowboy 4e38627a3d windows.cfg: Improved support for Windows types (ref. https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx ). 2018-05-16 09:16:12 +02:00
Daniel Marjamäki 21ab5c7591 Removed the generated cfg tests, these are not used. 2018-05-16 07:09:08 +02:00
IOBYTE ce50df8047 Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
Daniel Marjamäki 6bd4bdb0f9 Updated 'noValidConfiguration' message. It should not write this message when there is no code. It should be possible to see the preprocessor errors otherwise it is hard to fix the configuration. 2018-05-15 15:42:54 +02:00
Daniel Marjamäki f7746e4fb6 Revert "Missing override specifier warning on a pure virtual function makes no sense. (#1230)"
This reverts commit 348eb1c5c9.
2018-05-15 10:48:34 +02:00
orbitcowboy d0089fe305 windows.cfg: Added missing PFLOAT definition. 2018-05-15 09:43:28 +02:00
IOBYTE 348eb1c5c9 Missing override specifier warning on a pure virtual function makes no sense. (#1230)
This fixes a large number of false positives for cppcheck source code.
2018-05-14 23:08:40 +02:00
Daniel Marjamäki 66599b4ade astyle formatting
[ci skip]
2018-05-14 22:48:37 +02:00
umanamente d2d1bf900b (#8262) Added TODO test for "False positive: memory leak with shared_ptr stored in container" (#1228) 2018-05-14 13:08:33 +02:00
PKEuS 090a178ed6 Refactorization in SymbolDatabase: Do not redundantly store name in FriendInfo, and store FriendInfo in vector instead of list 2018-05-14 12:18:59 +02:00
PKEuS 4d549553b0 Small optimization in checkmemoryleak.cpp: Allow passing literals to addtoken()
Ran AStyle
2018-05-14 10:15:50 +02:00
Paul Fultz II 7ef714b0c6 Fix FP with duplicate assignments by checking if the expression is unique (#1223)
* Fix FP with duplicate assignments by checking if the expression is unique

* Use array of pointers

* Reorder scope condition
2018-05-13 20:20:55 +02:00