Paul Fultz II
9da574f4a0
Fix 11227: ValueFlow: Known value not set in condition for ternary operator ( #4653 )
...
* Evaluate args before function call
* Fix tests
* Format
* Add test for 11227
* Format
* Fix known condition
2022-12-18 22:07:43 +01:00
Oliver Stöneberg
dc5c5de10e
avoid some unnecessary copies ( #4589 )
2022-12-18 19:38:29 +01:00
chrchr-github
76c28073aa
Revert fix for #10831 ( #4631 )
2022-12-18 16:55:55 +01:00
chrchr-github
617cd29a41
Get type from auto ( #4640 )
2022-12-18 16:54:58 +01:00
chrchr-github
b1abaf8809
Fix FP useStlAlgorithm (don't suggest std::accumulate when nothing is accumulated) ( #4647 )
2022-12-18 16:52:04 +01:00
gerboengels
63e30d1b8c
Fix syntaxError on lambda inside decltype ( #4650 )
...
Use case where it gave an issue:
using customComparator = decltype([] (const X& lhs, const X& rhs) { return lhs.CompareTo(rhs); });
std::map<X, int, costomComparator> m;
Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
2022-12-18 16:46:04 +01:00
Daniel Marjamäki
7799f820a3
Refactoring: Use static for local function getMinMaxValues
2022-12-17 21:21:18 +01:00
Daniel Marjamäki
c736d60642
Fix Misra C++ warning 'Limited dependence should be placed on C++ operator precedence rules in expressions.'
2022-12-17 20:45:58 +01:00
chrchr-github
4c8aa56d8b
Partial fix for #11378 internalAstError regressions (iscpp11init) ( #4629 )
...
* Partial fix for #11378 internalAstError regressions (iscpp11init)
* Use %cop%
* Add test for #11229
* Format
* Format
2022-12-16 10:46:15 +01:00
Paul Fultz II
9c55b933c1
Partial fix for 11303: False negative: knownConditionTrueFalse using container .back() ( #4633 )
...
* Partial fix for 11303: False negative: knownConditionTrueFalse using container .back()
* Format
* Fix error message
2022-12-15 18:35:19 +01:00
Paul Fultz II
90898945c1
Fix 10532: False negative: dangling string_view when using ternary operator ( #4638 )
...
* Fix 10532: False negative: dangling string_view when using ternary operator
* Format
* Update
2022-12-15 18:34:43 +01:00
chrchr-github
553b579f8d
Fix #11434 FP knownConditionTrueFalse with loop over bool array ( #4646 )
...
* Fix #11434 FP knownConditionTrueFalse with loop over bool array
* Simplify
2022-12-15 14:31:02 +01:00
chrchr-github
0c1e2ceeb9
Fix #11289 FP wrongPrintfScanfArgNum - snprintf with parameter pack ( #4644 )
2022-12-15 08:52:13 +01:00
chrchr-github
b7693ccc7a
Fix #11431 FP resourceLeak with goto ( #4645 )
2022-12-14 22:47:14 +01:00
Oliver Stöneberg
29e0133cb5
extracted `FwdAnalysis` from `astutils.{cpp|h}` ( #4637 )
...
* added missing filtering offiles in Visual Studio project
* extracted `FwdAnalysis` from `astutils.{cpp|h}`
2022-12-13 22:29:23 +01:00
Paul Fultz II
e2f398f81a
Fix 11250: FN: bufferAccessOutOfBounds (comma operator: int x = (3,4) ) ( #4636 )
...
* Fix 11250: FN: bufferAccessOutOfBounds (comma operator: int x = (3,4) )
* Format
2022-12-13 07:52:58 +01:00
Oliver Stöneberg
e01c463ff8
fixed #11428 - improved handling of suffixes in `MathLib::to{Double|ULong|Long}Number()` ( #4635 )
...
* fixed #11428 - improved handling of suffices in `MathLib::to{Double|ULong|Long}Number()`
* testmathlib.cpp: adjustments for `libc++`
* mathlib.cpp: added TODO
2022-12-13 07:52:45 +01:00
Paul Fultz II
b4d455df48
Fix 11349: FP negativeIndex for clamped array index ( #4627 )
...
* Fix 11349: FP negativeIndex for clamped array index
* Format
* Use emplace_back
* Use default constructor
2022-12-13 07:50:01 +01:00
chrchr-github
5b687cb038
Fix #11423 Crash in valueFlowForwardConst() ( #4634 )
2022-12-12 22:58:48 +01:00
chrchr-github
3f5054035d
Fix #11432 FP passedByValue for overriden function ( #4632 )
2022-12-12 21:52:58 +01:00
Daniel Marjamäki
7aae78fed3
Refactoring: Remove unused parameter for AnalyzerInfo::reportErr
2022-12-11 21:27:16 +01:00
Paul Fultz II
3f88744851
Fix 11358: FP containerOutOfBounds for container passed by pointer ( #4626 )
2022-12-09 19:43:21 +01:00
Oliver Stöneberg
40a69e5afb
optimized deserializing of `ErrorMessage` and related main process code ( #4610 )
2022-12-09 19:34:51 +01:00
Paul Fultz II
6eccb2e36c
Throw internal error when tokens are not in order ( #4623 )
...
* Throw internal error when tokens are not in order
* Add semicolon
2022-12-09 07:17:16 +01:00
Paul Fultz II
7acbb656f3
Fix 11412: False positive: uninitvar ( #4624 )
...
* Dont remove modified variables from dead code
* Add test for 11412
* Format
2022-12-09 07:15:47 +01:00
Paul Fultz II
c150317f02
Fix 11384: FP knownConditionTrueFalse when variable is modified in return statement ( #4625 )
...
* Fix 11384: FP knownConditionTrueFalse when variable is modified in return statement
* Format
2022-12-09 07:15:15 +01:00
chrchr-github
c779cefa61
Fix #11422 debug: Missing variable class for variable with varid ( #4616 )
2022-12-08 20:17:06 +01:00
Paul Fultz II
0cb742701d
Fix 11415: FP containerOutOfBounds for container initialized in virtual method ( #4622 )
2022-12-08 20:10:58 +01:00
chrchr-github
04b7c0c200
Fix #11404 FP knownConditionTrueFalse with iterator ( #4619 )
...
* Fix wrong value set in valueFlowSameExpressions()
* Fix #11404 FP knownConditionTrueFalse with iterator
2022-12-08 10:40:55 +01:00
Paul Fultz II
663a8411dd
Fix 11416: FP nullPointerRedundantCheck for check after loop with break ( #4620 )
2022-12-08 07:27:06 +01:00
Oliver Stöneberg
4103d05c7f
improved `ErrorMessage::deserialize()` error messages ( #4617 )
2022-12-07 18:00:45 +01:00
chrchr-github
8713dabe58
Get type from iterator ( #4613 )
2022-12-07 09:38:36 +01:00
Oliver Stöneberg
8bb5ac0efd
improved `MathLib::to{ULong|Long|Double}Number()` and increased test coverage / added CMake option `USE_LIBCXX` / fixed #10695 ( #4611 )
2022-12-07 09:20:09 +01:00
chrchr-github
89dba226dd
Fix #11305 FP uninitvar with unseen typedef ( #4612 )
2022-12-07 09:14:22 +01:00
chrchr-github
0e57c27dd3
Fix #11386 debug: CheckClass::checkConst found unlinked template argument list ( #4614 )
2022-12-07 09:12:46 +01:00
chrchr-github
d5d7446433
Add cfg for std::scoped_lock, handle template arguments in checkMisusedScopedObject() ( #4615 )
2022-12-07 09:10:48 +01:00
Oliver Stöneberg
7d3ce62ee9
improved errorhandling related to deserializing `ErrorMessage` ( #4604 )
2022-12-03 15:44:33 +01:00
chrchr-github
0854fda28a
Get type from smartpointer ( #4608 )
...
* Fix #11223 checkLibraryFunction treats "auto" as type
* Use utility function
* Get type from 'auto p = new ...'
* Fix merge
* Add test for recent fix
* Format
* Get type from smartpointer
2022-12-03 07:50:21 +01:00
chrchr-github
7d6683fb78
Fix #11417 FP knownConditionTrueFalse with container and brace init ( #4606 )
...
* Fix #11417 FP knownConditionTrueFalse with container and brace init
* Format
* Format
* Move to getInitListSize()
2022-12-02 22:07:08 +01:00
chrchr-github
e4ee7cd59c
Get type from 'auto p = new ...' ( #4607 )
...
* Fix #11223 checkLibraryFunction treats "auto" as type
* Use utility function
* Get type from 'auto p = new ...'
* Fix merge
2022-12-02 20:28:14 +01:00
chrchr-github
9efedd6be9
Fix #11223 checkLibraryFunction treats "auto" as type ( #4605 )
...
* Fix #11223 checkLibraryFunction treats "auto" as type
* Use utility function
2022-12-02 07:21:33 +01:00
chrchr-github
428f5016d4
Partial fix for #11378 (iscpp11init) ( #4595 )
...
* Partial fix for #11378 (iscpp11init)
* Improve fix
* Add fix
2022-11-27 09:26:46 +01:00
chrchr-github
665e4230f2
Fix #11406 FP returnDanglingLifetime, std::unique_ptr and implicit conversion to bool ( #4600 )
2022-11-27 09:24:19 +01:00
chrchr-github
4cb49013a7
Fix #11374 FP danglingTemporaryLifetime with std::string_view ( #4602 )
2022-11-27 09:22:55 +01:00
Rikard Falkeborn
52264b9c26
Fix #11401 nullpointer dereference with alignof ( #4601 )
...
* checknullpointer: Don't report dereference with alignof
* Refactor unevaluating operator check in checknullpointer
Unifying these ensures the different checks treat the operators the
same.
* Fix FP with _Alignof and null pointer
Just like alignof, _Alignof does not evaluate its operand.
* CheckNullPointer: Also support compiler specific alignof
This fixes #11401 which is about __alignof__. For good measure, also add
the microsoft extensions __alignof and _alignof.
2022-11-27 09:20:19 +01:00
Rikard Falkeborn
8465d901c8
Fix 11396, doublefree on munmap in if-statement ( #4594 )
2022-11-26 15:45:27 +01:00
Stefan van Kessel
a5c16af16d
Fix lambda capture template syntax error ( #4593 )
2022-11-23 20:15:10 +01:00
chrchr-github
68acd77053
Fix #11361 FP ctuPointerArith with unknown buffer size ( #4591 )
2022-11-23 19:11:47 +01:00
Daniel Marjamäki
ad8c1e26f0
dump: output language to dumpfile
2022-11-20 12:30:09 +01:00
chrchr-github
9f50611a44
Fix #11391 FP doubleFree with goto ( #4587 )
2022-11-19 16:49:34 +01:00
chrchr-github
80aa6dc1d9
Fix #11392 FP mismatchAllocDealloc with std::unique_ptr and custom deleter ( #4585 )
2022-11-18 19:45:25 +01:00
gerboengels
3fdba645a6
Improve fix for #11383 FP selfAssignment: lambda capture ( #4584 )
2022-11-18 19:44:32 +01:00
chrchr-github
4ce76d0b58
Fix #11385 debug: SymbolDatabase::findFunction found '>' without link. ( #4583 )
2022-11-14 21:08:15 +01:00
chrchr-github
e3939d32d0
Fix crash on nullptr ( #4582 )
...
* Update tokenlist.cpp
* Update testincompletestatement.cpp
* Fix #11370 FP constStatement with lambda
* Format
* Fix crash on nullptr
* Emit syntax error
* Fix test
* Use strAt()
* Fix another crash on nullptr
* Update testconstructors.cpp
* Fix crash on nullptr
* Fix test
2022-11-13 23:04:51 +01:00
chrchr-github
701d381895
Fix #11383 FP selfAssignment: lambda capture / #11380 FP operatorEqRetRefThis ( #4581 )
...
* Fix #11383 FP selfAssignment: lambda capture / #11380
FP operatorEqRetRefThis
* Format
2022-11-13 21:20:44 +01:00
Daniel Marjamäki
8aec886450
runformat
2022-11-12 22:36:26 +01:00
chrchr-github
e8b37235d6
Fix #11378 internalAstError regressions (iscpp11init) ( #4580 )
2022-11-12 22:25:05 +01:00
Daniel Marjamäki
8fb8e06003
SymbolDatabase: Set valuetype for this
2022-11-12 22:23:42 +01:00
Daniel Marjamäki
15d3e510e1
ValueFlow: throw TerminateException in valueFlowGenericForward in case analysis is terminated
2022-11-12 12:47:54 +01:00
chrchr-github
4e75c08f58
Respect [[maybe_unused]] in unusedPrivateFunction ( #4579 )
2022-11-10 20:58:39 +01:00
chrchr-github
ffc0c57562
Fix crashes on nullptr ( #4575 )
2022-11-09 21:56:16 +01:00
gerboengels
bd95efc987
Fix internal error "Unexpected tokens in initializer" with anonymous namespace ( #4577 )
...
Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
2022-11-05 22:41:13 +01:00
Daniel Marjamäki
e45e5f9f15
SymbolDatabase: fix ValueType for '&array[x]'
2022-11-05 21:22:08 +01:00
Daniel Marjamäki
ecb2938e7e
SymbolDatabase: Set correct ValueType when there is array-to-pointer decay
2022-11-05 17:38:31 +01:00
gerboengels
d7a8f7f297
Fix couple issues with missing operatorEqVarError ( #4576 )
2022-11-05 10:48:34 +01:00
Rikard Falkeborn
3c21b9cc53
Fix #11038 , FP memory leak in if-statement in realloc with cast ( #4572 )
2022-11-03 10:37:43 +01:00
chrchr-github
e4c5f36af0
Fix #11373 typedef: not simplified after inline keyword ( #4574 )
2022-11-02 15:15:33 +01:00
chrchr-github
ccf2176664
Fix #11370 FP constStatement with lambda ( #4570 )
...
* Update tokenlist.cpp
* Update testincompletestatement.cpp
* Fix #11370 FP constStatement with lambda
* Format
2022-11-01 11:50:08 +01:00
chrchr-github
d717e62ec3
Fix #11371 Detect assignment to temporary ( #4571 )
...
* Fix #11371 Detect assignment to temporary
* Use AST
* Warn if type definition is not seen
2022-11-01 11:46:42 +01:00
chrchr-github
cf8051b7e2
Fix #11368 FP "Same value in both branches of ternary operator" on plus and minus zero ( #4569 )
...
Fix #11368 FP "Same value in both branches of ternary operator" on plus and minus zero
2022-10-31 15:18:25 +01:00
Daniel Marjamäki
e8606a5e5a
let --premium=misra-c-2012 also set --addon=misra. changed addons container to a set
2022-10-31 15:04:16 +01:00
chrchr-github
6df8573e15
Fix #11369 Syntax error. Unexpected tokens in initializer. ( #4568 )
2022-10-29 21:24:50 +02:00
chrchr-github
b4e78e8ac5
Fix #11357 new internalAstError ( #4564 )
...
* Fix #11357 new internalAstError
* Format
* Handle scope operator
* Format
* Format
2022-10-25 21:50:37 +02:00
chrchr-github
13d81cdd58
#11351 follow-up: Handle more variadic template arguments ( #4554 )
...
* Update templatesimplifier.cpp
* Add tests
2022-10-22 00:28:33 +02:00
chrchr-github
ae16aab997
Handle simple typedefs ( #4558 )
2022-10-22 00:28:05 +02:00
chrchr-github
e046232535
Fix #11362 FP returnDanglingLifetime for pointer to struct member in static array ( #4563 )
...
* Fix #11362 FP returnDanglingLifetime for pointer to struct member in static array
* Undo
2022-10-22 00:27:30 +02:00
chrchr-github
515369739c
Fix #11359 FP constStatement for function-local struct definition+initialization statement ( #4561 )
2022-10-22 00:27:19 +02:00
Razvan Ioan Alexe
1da37461e3
Typo found in Summary of CWE: 758 ( #4553 )
2022-10-20 19:11:15 +02:00
chrchr-github
7b9c99003b
Improve unreachableCodeError: handle library functions ( #4560 )
...
* Update templatesimplifier.cpp
* Add tests
* Improve unreachableCodeError message
* Update templatesimplifier.cpp
* Add tests
* Improve unreachableCodeError message
* Revert "Update templatesimplifier.cpp"
This reverts commit 3fd152ed4063772a5f162bd985c3d91bcc65eb55.
* Revert "Add tests"
This reverts commit e760ab51e66a0a2c3a0250caf4cf3b745db44d10.
* Improve unreachableCodeError: handle library functions
* Fix merge
2022-10-20 07:00:36 +02:00
chrchr-github
9c7b4c9540
Improve unreachableCodeError message ( #4559 )
...
* Update templatesimplifier.cpp
* Add tests
* Improve unreachableCodeError message
* Update templatesimplifier.cpp
* Add tests
* Improve unreachableCodeError message
* Revert "Update templatesimplifier.cpp"
This reverts commit 3fd152ed4063772a5f162bd985c3d91bcc65eb55.
* Revert "Add tests"
This reverts commit e760ab51e66a0a2c3a0250caf4cf3b745db44d10.
2022-10-19 19:19:31 +02:00
chrchr-github
192c30ab1d
Fix crash in arraySize() ( #4556 )
...
* Fix #11355 FN: arrayIndexOutOfBounds
* Fix
* Fix crash in arraySize()
2022-10-19 19:19:01 +02:00
gerboengels
6a01fa9b70
#11134 Fix broken AST with (designated) initializers ( #4550 )
...
* Make control flow a bit easier, and more similar to previous code
Made similar to around line 790
* In a cpp11init, always parse only the corresponding } (#11134 )
- _always_, because in some cases this was omitted (around line 790) or too strict (around line 860)
- _only_, and not following tokens which happen to be } as well (around line 1030)
* Fix unit tests: AST was incorrect, now is fixed
auto var{ {{},{}}, {} };
Old AST:
```
{
|-var
`-{
`-,
|-,
| |-{
| `-{
`-{
```
New AST:
```
{
|-var
`-,
|-{
| `-,
| | |-{
| | `-{
`-{
```
Compare the same example, but with `X{}` instead of just `{}`:
`auto var{ a{b{},c{}}, d{} };`
```
{
|-var
`-,
|-{
| |-a
| `-,
| | |-{
| | | `-b
| | `-{
| | | `-c
`-{
`-d
```
This structure is similar to that of the new AST, not the old AST
* Fix unit tests: another AST was incorrect, now is fixed
Code: `auto var{{1,a::b{2,3}}, {4,a::b{5,6}}};`
Old AST:
```
{
|-var
`-{
`-,
|-,
| |-1 'signed int'
| `-{
| | |-::
| | | |-a
| | | `-b
| | `-,
| | | |-2 'signed int'
| | | `-3 'signed int'
`-{
`-,
|-4 'signed int'
`-{
|-::
| |-a
| `-b
`-,
|-5 'signed int'
`-6 'signed int'
```
New AST:
```
{
|-var
`-,
|-{
| `-,
| | |-1 'signed int'
| | `-{
| | | |-::
| | | | |-a
| | | | `-b
| | | `-,
| | | | |-2 'signed int'
| | | | `-3 'signed int'
`-{
`-,
|-4 'signed int'
`-{
|-::
| |-a
| `-b
`-,
|-5 'signed int'
`-6 'signed int'
```
* Fix unit tests: missing ; after class, resulting in incorrectly being marked as cpp11init
Because of the missing `;` after the class declaration, it was marked as a cpp11init block.
Which it isn't, and which now throws an exception
* Fix cpp11init to let unit tests pass again
The following unit tests failed on the newly introduced throws, because the code for these tests incorrectly marked some tokens as cpp11init:
TestVarID::varid_cpp11initialization
TestTokenizer::checkRefQualifiers
* Fix typo
* Improve check for void trailing return type
Observation: the only function body _not_ containing a semicolon, is a void function: something like
auto make_zero(ini& i) -> void {
while(--i > 0) {}
}
Non-void function? Then it must return a value, and thus contain a semicolon, which is checked for a few lines later.
* Fix cpp11init with templated trailing return type
In the following example, vector was marked as cpp11init due to the mismatch of `%any% {`
auto f() -> std::vector<int> { return {}; }
I made the assumption that whenever "%any% {" matches, endtok must be set too.
If this assumtion doesn't hold (so "%any% {" matches, but endtok == nullptr), then the for-loop would search all the way to the end of stream. Which I guess was not the intention.
* Remove comments
Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
2022-10-19 07:25:15 +02:00
chrchr-github
5a8e55c083
Fix #11355 FN: arrayIndexOutOfBounds ( #4555 )
...
* Fix #11355 FN: arrayIndexOutOfBounds
* Fix
2022-10-18 07:24:24 +02:00
chrchr-github
c6c339a3e7
Fix #11351 Assert failure in templatesimplifier.cpp ( #4552 )
2022-10-16 19:34:25 +02:00
gerboengels
221873e69f
Fix #11319 ( #4549 )
...
In this example:
```
//template<std::same_as<int> T> // <= works
template<same_as<int> T> // <= didn't work
void f()
{}
```
the changed line used to match to `< same_as <`, therefore skip creating links.
The `%op% %name% <` already feels a bit like a workaround. So adding the condition that $op$ shouldn't be a comparison operator, but part of the template, seemed reasonable to me
Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
2022-10-16 19:33:44 +02:00
Oliver Stöneberg
2ac9fbc1bf
include all (internal non-generated) headers in clang-tidy checks ( #4100 )
2022-10-16 13:51:17 +02:00
chrchr-github
3273e51fd5
Fix #10412 FN useStlAlgorithm with iterators ( #4157 )
2022-10-16 13:46:26 +02:00
chrchr-github
6c24d2b865
Fix #11321 FP uninitvar for in-class member initialization ( #4547 )
2022-10-14 19:48:27 +02:00
Daniel Marjamäki
b8b6be48d9
Fixed #9926 (False positive assertWithSideEffects, calling method that has no side effects)
2022-10-12 07:51:50 +02:00
Daniel Marjamäki
2a81388c95
Fixed #11102 (False positive: unreadVariable when union in derived struct is used)
2022-10-11 20:47:07 +02:00
Daniel Marjamäki
584a428025
Fixed #10831 ("Analysis failed (lambda not recognized)" with lamba default parameter in lambda signature)
2022-10-10 21:05:48 +02:00
gerboengels
ed06e29f7a
Fix defaulted and deleted functions ( #4540 )
...
* Fix 9392, but for destructors: out-of-line defaulted destructors skipped everything after
Context:
```
struct S {
~S();
};
S::~S() = default;
void g() {
int j;
++j;
}
```
Everything after `S::~S() = default;` was skipped, so the uninitialized variables in g() weren't found.
Out-of-line destructors are useful e.g. when you have a forward declared unique_ptr in the .h,
and `= default` the destructor in the .cpp, so only the cpp needs to know the header for destructing
your unique_ptr (like in the pImpl-idiom)
* Fix unit test, by correctly fixing 10789
Previous commit broke this test, but also provided the tools for a cleaner fix
* Document current behaviour
* Rewrite control flow
* Fix deleted functions, which skipped everything after
`a::b f() = delete` triggered the final else in SymbolDatabase::addNewFunction,
which sets tok to nullptr, effectively skipping to the end of the stream.
* Remove troublesome nullptr, which skips every analysis afterwards
It was introduced in 0746c241
to fix a memory leak.
But setting tok to nullptr, effectively skipping to the end, seems not needed.
Previous commits fixes prevented some cases where you could enter the `else`.
This commit is more of a fall back.
* fixup! Fix deleted functions, which skipped everything after
`a::b f() = delete` triggered the final else in SymbolDatabase::addNewFunction,
which sets tok to nullptr, effectively skipping to the end of the stream.
* fixup! Fix deleted functions, which skipped everything after
`a::b f() = delete` triggered the final else in SymbolDatabase::addNewFunction,
which sets tok to nullptr, effectively skipping to the end of the stream.
* Make it heard when encountering unexpected syntax/tokens
Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
2022-10-10 20:17:33 +02:00
Daniel Marjamäki
65cd6ea7b4
Clarify knownConditionTrueFalse warnings
2022-10-10 13:45:30 +02:00
Paul Fultz II
bd22ea565f
Use return instead of condition for alwaysTrueFalse check ( #4446 )
2022-10-09 21:03:48 +02:00
Oliver Stöneberg
fa7e08a29f
optimized `CheckOther::checkDuplicateBranch()` a bit ( #4542 )
2022-10-09 20:48:54 +02:00
Oliver Stöneberg
d1bfae989e
fixed handling of incomplete char/string literals in `isPrefixStringCharLiteral()` - also optimized it a bit ( #4541 )
...
* fixed handling of incomplete char/string literals in `isPrefixStringCharLiteral()` - also optimized it a bit / added tests for `isStringLiteral()` and `isCharLiteral()`
* utils.h: early out in `isStringCharLiteral()` to avoid the loop
2022-10-09 11:19:19 +02:00
Oliver Stöneberg
9f7a725983
added environment variable `UNUSEDFUNCTION_ONLY` to make sure only the `unusedFunction` check is being executed ( #4362 )
2022-10-06 20:54:24 +02:00
Oliver Stöneberg
7ead32f96e
various optimizations ( #4535 )
...
* avoid potentially duplicated `strTolower()` call in `Path::getFilenameExtensionInLowerCase()`
* avoid unnecessary copies
* use `unordered_*` containers for faster lookups
* symboldatabase.cpp: do not perform call in `checkReturns()` until needed
* astutils.cpp: do not perform calls in `isVariableChangedByFunctionCall()` until necessary
* tokenize.cpp: small `hasIfDef()` optimization
* use `unordered_map` for `CheckUnusedFunctions::FunctionUsage::mFunctions` / adjusted test case
2022-10-06 20:12:07 +02:00
Daniel Marjamäki
ca32cf11ba
Fix handling of --performance-valueflow-max-time=T
2022-10-04 20:01:19 +02:00
Daniel Marjamäki
8686997292
Add experimental option --performance-valueflow-max-time=T
2022-10-04 14:02:55 +02:00
Oliver Stöneberg
ee124cd097
modernized `erase()` calls ( #4530 )
2022-10-02 07:13:31 +02:00
Oliver Stöneberg
cff1cd9cda
applied clang-tidy `misc-const-correctness` fixes for POD types, iterators and references ( #4529 )
...
* applied `misc-const-correctness` fixes for POD types and iterators
* applied `misc-const-correctness` fixes for references
2022-10-02 07:12:40 +02:00
chrchr-github
586c29c772
Partial fix for #9157 False negative: stlOutOfBounds, cast ( #4527 )
...
* Fix leakNoVarFunctionCall FP
* Partial fix for #9157 False negative: stlOutOfBounds, cast
2022-09-30 14:43:21 +02:00
chrchr-github
4d13266e99
Fix #10083 FN unusedScopedObject: temporary lock 'std::lock_guard<std::mutex>(m)' ( #4522 )
...
* Fix #10083 FN unusedScopedObject: temporary lock 'std::lock_guard<std::mutex>(m)'
* Format
* Fix cppcheck-cfg.rng
* Format
2022-09-30 07:25:33 +02:00
Oliver Stöneberg
3dfdb409c6
fixed and enabled some Clang compiler warnings ( #4517 )
2022-09-29 21:59:02 +02:00
chrchr-github
6142ba542a
Fix leakNoVarFunctionCall FP ( #4523 )
2022-09-29 21:58:11 +02:00
chrchr-github
260a757791
Fix #10839 internalAstError with function returning a function ( #4514 )
2022-09-29 21:56:26 +02:00
Oliver Stöneberg
083efe6361
astutils.h: use pre-sized SmallVector in visitAstNodes() ( #3919 )
2022-09-29 21:52:42 +02:00
Oliver Stöneberg
eeb6db05f1
avoid some unnecessary object creations and copies ( #4493 )
2022-09-29 21:47:17 +02:00
Oliver Stöneberg
0481edf9c3
return `SmallVector` from `followAllReferences()` ( #3925 )
2022-09-29 21:41:32 +02:00
chrchr-github
b8b6b41833
Fix #10802 Broken AST lambda inside for loop ( #4520 )
...
* Fix #10802 Broken AST lambda inside for loop
* Add some boost and wxwidget defines (on behalf of "david ingamells")
2022-09-29 13:29:50 +02:00
chrchr-github
56e2af5dec
Fix #9653 FP leakReturnValNotUsed although (void) is specified ( #4431 )
2022-09-27 20:09:04 +02:00
Oliver Stöneberg
d6f1d7bb23
replaced `static const`/fixed `std::vector` containers with `std::array` ( #4440 )
2022-09-27 20:06:15 +02:00
Oliver Stöneberg
10426f6707
cppcheck.cpp: only call `getFileInfo()` if necessary ( #4510 )
2022-09-27 20:04:35 +02:00
Oliver Stöneberg
b9e07e918e
enabled and fixed `readability-named-parameter` clang-tidy warnings ( #4487 )
2022-09-27 20:03:25 +02:00
chrchr-github
cab4997b0b
Fix #11039 Empty AST with delete new / #11327 FP leakReturnValNotUsed with new and offset ( #4513 )
...
* Fix internalAstError with new
* Format
* nullptr check
* Add test for #11039
* Fix #11039 Empty AST with delete new / #11327 FP leakReturnValNotUsed with new and offset
2022-09-27 18:12:58 +02:00
Maksim Derbasov
c8b96c3a20
Typos fix ( #4509 )
2022-09-27 06:48:06 +02:00
chrchr-github
0f79f8bd70
Fix internalAstError with new ( #4508 )
...
* Fix internalAstError with new
* Format
* nullptr check
2022-09-26 22:05:58 +02:00
chrchr-github
64f3f85804
Fix #11332 Function::addArguments found argument 'b' with varid 0 wit… ( #4506 )
...
* Fix #11332 Function::addArguments found argument 'b' with varid 0 with lambda parameter
* Fix varid0 warning
2022-09-26 18:21:21 +02:00
Paul Fultz II
fc39a4d1bb
Fix 11171: False positive: missing return statement when std::enable_if_t is used ( #4504 )
...
* Fix 11171: False positive: missing return statement when std::enable_if_t is used
* Format
* Return false
* Workaround bug in cppcheck
2022-09-26 18:20:42 +02:00
Oliver Stöneberg
657d9143f7
cleaned up includes based on include-what-you-use ( #4502 )
...
* iwyu.yml: include internal check sources
* cleaned up includes based on include-what-you-use
2022-09-25 09:20:34 +02:00
Leila F. Rahman
70c844ddfb
Fix the release function in the ValuePtr class ( #4490 )
2022-09-24 13:25:06 +02:00
chrchr-github
2808fc615e
Fix #10057 "statement without effect" / #4779 FN unusedScopedObject does not work for classes in different namespace ( #4500 )
...
* Partial fix for #10057 unused variable without assignment not detected
* Add test for #9672
* Fix #4779 FN unusedScopedObject does not work for classes in different namespace
* Merge
* Fix #10057 "statement without effect" (unused variable without assignment) not detected
* Format
2022-09-24 12:49:37 +02:00
Oliver Stöneberg
dc03a50414
some small cleanups and refactorings ( #4488 )
...
* moved `plistFile` from `ErrorLogger` to `CppCheck`
* got rid of global CWE objects
* lib/CMakeLists.txt: suppress some `-Wfloat-equal` clang warning in matchcompiled builds as well
* lib/CMakeLists.txt: moved a loop into proper block
* test/CMakeLists.txt: simplified `add_fixture`
* test/CMakeLists.txt: moved `fixture_cost`
* fixed `naming-privateMemberVariable` selfcheck warning
2022-09-24 11:59:13 +02:00
Oliver Stöneberg
e8b9cd64fc
refs #10663 - only match start pattern in `Library::detectContainerInternal()` if necessary ( #4499 )
2022-09-23 20:19:56 +02:00
chrchr-github
d608bec414
Fix FP with std::array ( #4497 )
...
* Fix #1655 wrong usage of std::string in memcpy
* Fix memsetClass FP
* Fix #8619 FN memset on container containing structs with containers
* Token::Match
* Use AST
* simpleMatch
* Fix FP with std::array
* simpleMatch
2022-09-23 20:18:49 +02:00
chrchr-github
0bb82b70d9
Fix #11328 FN functionStatic, functionConst with this ( #4496 )
...
* Fix #11328 FN functionStatic, functionConst with this
* Fix FP
2022-09-23 08:46:31 +02:00
Jim Kuhn
f27fbdd8ab
Fix sense of test (.analyzerinfo files get placed in wrong directory) ( #4486 )
...
* Fix sense of test (.analyzerinfo files get placed in wrong directory)
* Update testanalyzerinformation.cpp
style (tabs -> spaces)
2022-09-21 17:38:23 +02:00
chrchr-github
3b07661fd3
Fix #11293 debug: CheckClass::isMemberVar found used member variable 'x' with varid 0 ( #4489 )
2022-09-21 17:35:10 +02:00
chrchr-github
2aca275e0c
Fix #8619 FN memset on container containing structs with containers ( #4491 )
...
* Fix #1655 wrong usage of std::string in memcpy
* Fix memsetClass FP
* Fix #8619 FN memset on container containing structs with containers
* Token::Match
* Use AST
* simpleMatch
2022-09-21 17:33:48 +02:00
chrchr-github
3644d79162
Fix duplicateConditionalAssign FP ( #4484 )
...
* Fix #9406 FN redundant assignment of Boolean variable
* Fix warning, refactor
* Update testcondition.cpp
* Fix duplicateConditionalAssign FP
* Format
2022-09-20 21:57:27 +02:00
chrchr-github
dcb332acb0
Fix #9406 FN redundant assignment of Boolean variable ( #4482 )
...
* Fix #9406 FN redundant assignment of Boolean variable
* Fix warning, refactor
* Update testcondition.cpp
2022-09-20 07:30:12 +02:00
chrchr-github
f274d499a1
Fix #11171 FP missing return statement when std::enable_if_t is used ( #4480 )
...
* Fix #11171 FP missing return statement when std::enable_if_t is used
* Add check
2022-09-19 12:47:58 +02:00
Daniel Marjamäki
8275f07692
dump: Add Token::isCast attribute
2022-09-18 12:42:58 +02:00
Paul Fultz II
09944c0b7e
Fix 11298: FP danglingTemporaryLifetime when constructing from const char* ( #4479 )
...
* Fix 11298: FP danglingTemporaryLifetime when constructing from const char*
* Format
2022-09-18 08:30:58 +02:00
Paul Fultz II
de7d02293f
Fix 11308: FP accessMoved with virtual function ( #4478 )
...
* Fix 11308: FP accessMoved with virtual function
* Format
2022-09-18 08:30:06 +02:00
Paul Fultz II
d34de745c0
Fix 11306: FP knownConditionTrueFalse with strlen() ( #4477 )
...
* Fix 11306: FP knownConditionTrueFalse with strlen()
* Add another test
2022-09-18 08:29:10 +02:00
chrchr-github
cb6f04a16c
Fix #11315 FP zerodivcond from enum definition / #11310 FP unassignedVariable with static variable ( #4476 )
...
* Fix #11315 FP zerodivcond from enum definition
* Simplify Boolean expression
* Fix #11310 FP unassignedVariable with static variable
2022-09-17 18:50:07 +02:00
Sergei Trofimovich
3b840e7ff1
lib/sourcelocation.h: add missing <cstdint> include ( #4474 )
...
Without the change build on upcoming gcc-13 fails as:
In file included from lib/symboldatabase.h:28,
from lib/astutils.h:36,
from test/testastutils.cpp:20:
lib/sourcelocation.h:52:10: error: 'uint_least32_t' in namespace 'std' does not name a type
52 | std::uint_least32_t m_line = 0;
| ^~~~~~~~~~~~~~
2022-09-16 21:36:37 +02:00
Oliver Stöneberg
897826006e
mitigated some clang-tidy warnings in headers ( #4472 )
...
* erroritem.h: avoid `performance-no-int-to-ptr` clang-tidy warning
* suppress `readability-inconsistent-declaration-parameter-name` clang-tidy warnings for Qt signals
* tokenlist.h: mitigated `readability-make-member-function-const` clang-tidy warnings
* fixed `modernize-use-override` clang-tidy warnings in headers
* fixed `modernize-pass-by-value` clang-tidy warnings in headers
* tokenize.cpp: avoid unnecessary copy
2022-09-16 18:59:15 +02:00
Oliver Stöneberg
339484d2a1
mitigated and enabled more clang-tidy warnings ( #4470 )
...
* fixed some `performance-inefficient-string-concatenation` clang-tidy warnings
* fixed and enabled `modernize-replace-random-shuffle` clang-tidy warning
* fixed and enabled `bugprone-suspicious-string-compare` clang-tidy warning
* mitigated and enabled `readability-non-const-parameter` clang-tidy warnings
* clang-tidy.md: documented some disabled checks
* mitigated and enabled `performance-unnecessary-value-param` clang-tidy warnings
2022-09-16 18:58:59 +02:00
chrchr-github
45ccc9ba1e
Fix ctunullpointer FP ( #4471 )
2022-09-16 12:11:34 +02:00
Oliver Stöneberg
b3ec225480
iwyu.yml: use `debian:unstable` to always get latest include-what-you-use / cleaned up includes ( #4466 )
...
* iwyu.yml: use debian:unstable to always get latest include-what-you-use
* cleaned up includes based on include-what-you-use
* mitigated include-what-you-use false positives
2022-09-16 07:15:49 +02:00
chrchr-github
c9ade33298
Fix memsetClass FP ( #4465 )
2022-09-15 20:20:49 +02:00
Daniel Marjamäki
f1aa9eb48f
dump: add externLang attribute for tokens
2022-09-15 19:57:42 +02:00
chrchr-github
d1386a842a
Fix #11301 debug: constStatementError not handled. ( #4463 )
...
* Fix #11301 debug: constStatementError not handled.
* Use function
2022-09-14 23:57:02 +02:00
chrchr-github
266174ddc4
Fix #10993 danglingTemporaryLifetime reported in two different locati… ( #4462 )
...
* Fix #10993 danglingTemporaryLifetime reported in two different locations for std::string_view usage
* Missing include
* Add test
2022-09-14 07:28:04 +02:00
chrchr-github
07caf17eb3
Fix #1655 wrong usage of std::string in memcpy ( #4460 )
2022-09-13 15:14:25 +02:00
chrchr-github
e904f7341e
Fix ValueFlow crash ( #4461 )
2022-09-13 12:25:15 +02:00
Paul Fultz II
43caa32abf
Fix 9755: false negative: access of moved variable in conditional code ( #4459 )
...
* Fix 9755: false negative: access of moved variable in conditional code
* Format
2022-09-11 12:32:01 +02:00