Commit Graph

77 Commits

Author SHA1 Message Date
Oliver Stöneberg 171da2e6f9
avoid dependency on transitive includes - based on include-what-you-use (#3757) 2022-01-27 19:03:20 +01:00
chrchr-github 0c16e346f1
Minor: add endsWith() template, empy() check (#3472) 2021-09-28 20:34:21 +02:00
Oliver Stöneberg 6397e29f84
cleaned up includes based on include-what-you-use (#3141) 2021-04-03 21:30:50 +02:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
PKEuS 141d2ac215 Refactorization: Improved internal implementation of severity and certainty levels
Backported from LCppC.
2021-02-24 22:00:06 +01:00
PKEuS 29a6031cea Fixed more false negatives (and recently introduced false positives) literalWithCharPtrCompare by using ValueType
Merged from LCppC.
2021-02-20 13:29:59 +01:00
PKEuS 423d7dbc3c Fixed false negatives literalWithCharPtrCompare when address-of operator (C only) or arrays are used, adapted TODO unit tests
Enabled working unit test in testunusedvar.cpp

Merged from LCppC.
2021-02-20 12:42:48 +01:00
Rikard Falkeborn 82fe6193fa Refactor: Use visitAstNodes in checkstring 2020-07-20 10:25:00 +02:00
Daniel Marjamäki 37245a8179 Update copyright year 2020-06-13 16:37:12 +02:00
Daniel Marjamäki 44ff22f879 Fixed #9276 (FP literalWithCharPtrCompare) 2020-06-06 17:47:30 +02:00
Oliver Stöneberg 37bc0483a4
made check.h less heavy (#2633) 2020-05-23 07:16:49 +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
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
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
Rikard Falkeborn 2a17e624d9 Overlapping sprintf, improve handling of casts (#1945)
* Overlapping sprintf, improve handling of casts

If there is a cast of the argument buffer, cppcheck would print out the
expression including the cast, which looks a bit strange to talk about

    Variable (char*)buf is used as...

Instead, only print the variable name without the cast.

Also, handle arbitrary many casts (the previous code only handled one).
Multiple casts of the input arguments is probably an unusual case in
real code, but can perhaps occur if macros are used.

* Fix printing of variable

... and add a test.

* Simplify testcase
2019-07-05 12:27:39 +02:00
Daniel Marjamäki 84cc09d17c Update Copyright 2019-06-29 07:49:14 +02:00
Rikard Falkeborn 295153df72 Checkstring fixes (#1783)
* teststring.cpp: Fix ternary syntax in tests

* stringLiteralWrite: Add tests wide character and utf16 strings

* suspiciousStringCompare: Add test with wide character string

* strPlusChar: Handle wide characters

* incorrectStringCompare: Add test with wide string

* Suspicious string compare: suggest wcscmp for wide strings

* deadStrcmp: Extend to handle wide strings

* sprintfOverlappingData: Print name of strcmp function

* Conversion of char literal to boolean, add wide character tests

* Conversion of char literal to boolean, fix ternary
2019-04-06 06:54:38 +02:00
Daniel Marjamäki f1146e398a Moved CheckString::sprintfOverlappingData from runSimplifiedChecks to runChecks 2019-02-25 09:23:03 +01:00
rikardfalkeborn a3e717bea9 Use functions instead of comparing with enum (#1471)
* Use isComparisonOp() instead of enum

* Use isAssignmentOp() instead of enum
2018-11-09 06:30:41 +01:00
Paul Fultz II f65cf220ba Fix false positives in unknownEvaluationOrder when using followVar (#1391)
Fix false positives in unknownEvaluationOrder when using followVar
2018-09-28 08:38:24 +02:00
Daniel Marjamäki be4ae66e36 Fix wrong message 2018-08-12 08:01:15 +02:00
Daniel Marjamäki f2e7071922 Fix FP, conversion of char literal '\0' to boolean is not true 2018-08-08 19:04:10 +02:00
Daniel Marjamäki 58c91c4645 Revert "Refactoring endsWith utility function"
This reverts commit d300d1f61b.
2018-07-25 16:14:43 +02:00
Daniel Marjamäki d300d1f61b Refactoring endsWith utility function 2018-07-25 07:43:50 +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
Daniel Marjamäki 2963522d5f Refactoring: Use ranged for loops 2018-07-13 16:40:15 +02:00
Daniel Marjamäki 79ffe1d4fc Rename _tokenizer, _settings, _errorLogger 2018-06-16 16:10:28 +02:00
orbitcowboy 33777c5b72 Improved const correcntess of local variables. 2018-05-29 13:24:48 +02:00
Daniel Marjamäki f336c2efe7 Refactoring; Renamed Scope::classStart and Scope::classEnd 2018-04-27 22:36:30 +02:00
Daniel Marjamäki a0906140a6 Suppressions: New extensible Suppressions xml format that allow more attributes. To start with it also allows symbolName. 2018-04-09 06:43:48 +02:00
jrp2014 b6504c70ca Improve constness 2018-04-04 21:51:31 +02:00
Daniel Marjamäki 7e4dba6a7e Updated copyright year 2018-03-31 20:59:09 +02:00
Martin Ettl 9816358e8b Cleanup not needed variable. 2018-01-19 22:41:51 +01:00
Daniel Marjamäki c4caee6b18 Updated copyright year 2018-01-14 15:37:52 +01:00
Daniel Marjamäki d292434e76 Try again to clarify warning message for new strcmp() checker 2017-12-13 15:28:50 +01:00
Daniel Marjamäki 3f36d4b5f4 try to clarify error message 2017-12-11 22:10:00 +01:00
Daniel Marjamäki 43db6147d3 astyle formatting
[ci skip]
2017-11-27 23:32:20 +01:00
Daniel Marjamäki f28d5e91ac Fixed #8251 (Condition: bug when there are more than 2 strcmp() on same buffer (tricky)) 2017-11-27 12:55:20 +01:00
Ayaz Salikhov 28aa939d69 iwyu - include what you use 2017-05-27 04:33:47 +02:00
Daniel Marjamäki 198c8878ee Use Token::simpleMatch() for simple pattern 2017-04-23 12:14:14 +02:00
Daniel Marjamäki f2719ec6ca Refactoring CheckString::sprintfOverlappingData. Use AST, isSameExpression(), getArguments(), .. 2017-04-23 10:51:31 +02:00
Daniel Marjamäki f92ef7d8e2 Refactoring. Use 'endsWith()' 2017-04-23 10:17:35 +02:00
PKEuS b1f4bd7504 Refactorization: Reimplemented Settings::_enabled as a bitfeld instead of std::set (#7995) 2017-04-11 11:49:26 +02:00
Daniel Marjamäki d09a8dde57 Improved char literal handling. In the 'normal' tokenlist these should not be simplified to integer literals. 2016-10-12 10:20:24 +02:00
Daniel Marjamäki 0e785e435e charLiteralWithCharPtrCompare: Improved warning to catch any char literal 2016-10-09 11:39:20 +02:00
Roberto Martelloni 28f1222dc2 CWE mapping of useAutoPointerMalloc, uselessCallsCompare, uselessCallsSwap, uselessCallsSubstr, uselessCallsEmpty, uselessCallsRemove, derefInvalidIterator, reademptycontainer, multiplySizeof, divideSizeof, stringLiteralWrite, incorrectStringCompare, literalWithCharPtrCompare, charLiteralWithCharPtrCompare, incorrectStringBooleanError, staticStringCompare, stringCompare, signConversion, truncLongCastAssignment, truncLongCastReturn, unusedFunction, unusedVariable, unusedAllocatedMemory, unreadVariable, unassignedVariable, unusedStructMember, postfixOperator, va_start_wrongParameter (#824)
Add an optional extended description…
2016-09-03 00:31:35 +02:00
Daniel Marjamäki 920ac5a3f6 astyle formatting
[ci skip]
2016-07-16 21:21:24 +02:00
Roberto Martelloni 25525e38a7 CWE mapping of incorrectStringCompare, literalWithCharPtrCompare, charLiteralWithCharPtrCompare, incorrectStringBooleanError, staticStringCompare, stringCompare, signConversion, unusedFunction, unusedVariable 2016-07-16 10:07:06 +01:00
PKEuS c7b3836379 Small refactorizations:
- Optimized performance of several functions by adding pre-checks
- Simplified some code
- Fixed VS warning in testsymboldatabase.cpp
2016-05-25 15:30:49 +02:00
Roberto Martelloni 50fc784550 Mapped error ids stlBoundaries, stlcstr, useAutoPointerContainer, useAutoPointerArray, sprintfOverlappingData, strPlusChar, shiftTooManyBits, integerOverflow, uninitstring, uninitdata, uninitvar, uninitStructMember, deadpointer, va_start_referencePassed, va_end_missing, va_list_usedBeforeStarted, va_start_subsequentCalls to their CWEs. 2016-02-03 12:53:23 +00:00