Daniel Marjamäki
64953f36b3
Clang import: CXXRecordDecl, CXXMethodDecl
2020-01-08 19:32:04 +01:00
Daniel Marjamäki
5ffd6d744c
Clang import; fix Cppcheck warnings about unused variables
2020-01-08 18:55:28 +01:00
Daniel Marjamäki
54a9b61329
Clang import; NamespaceDecl, varDecl4, varDecl5
2020-01-08 18:23:40 +01:00
Daniel Marjamäki
b8ae957365
Clang import; fwrite FunctionDecl
2020-01-08 16:42:21 +01:00
Daniel Marjamäki
c4c929a6a7
Clang import: StringLiteral, funcdecl3, determine includes with clang -v
2020-01-08 16:36:51 +01:00
Daniel Marjamäki
f51048e03b
Clang Import; TypedefDecl
2020-01-08 14:25:09 +01:00
Daniel Marjamäki
e6ee29fd11
Clang import; BreakStmt, ContinueStmt
2020-01-08 12:29:54 +01:00
Daniel Marjamäki
ea414e46e1
Clang import; WhileStmt
2020-01-08 12:19:48 +01:00
Daniel Marjamäki
61039023b2
Clang import; ForStmt
2020-01-08 10:35:44 +01:00
Daniel Marjamäki
4b7e6c68b0
Clang import; MemberExpr
2020-01-08 09:51:35 +01:00
Daniel Marjamäki
d75d9c1866
Clang import; Refactoring
2020-01-07 19:51:44 +01:00
Daniel Marjamäki
e5b99d3299
Clang import; Refactoring
2020-01-07 19:47:06 +01:00
Daniel Marjamäki
a3abc75ca1
Clang import; RecordDecl
2020-01-07 18:33:24 +01:00
Daniel Marjamäki
c4131bbc5b
Clang import; else
2020-01-07 12:38:37 +01:00
Daniel Marjamäki
b829c4cebb
Clang import; Arrays
2020-01-07 12:19:06 +01:00
Daniel Marjamäki
2760d4400b
SymbolDatabase: Ensure parameter name is same
2020-01-06 18:56:01 +01:00
Daniel Marjamäki
6a4a59b783
Clang Import; Added test
2020-01-06 16:45:18 +01:00
Daniel Marjamäki
28688dcc09
Clang Import; set Token::function()
2020-01-06 15:26:21 +01:00
Daniel Marjamäki
8ea22edb4e
Clang Import; VarDecl
2020-01-06 13:47:19 +01:00
Daniel Marjamäki
00c05ce626
Clang import; CallExpr, setLocation
2020-01-06 09:05:39 +01:00
Ken-Patrick Lehrmann
b6d2c1b238
Fix github CI ( #2477 )
...
* Fix github CI
```
Checking lib/check.cpp: __CPPCHECK__=1...
lib/symboldatabase.h:719:5: warning: Class 'Function' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
Function(const Token *tokenDef);
^
Checking lib/templatesimplifier.cpp: __CPPCHECK__=1...
lib/symboldatabase.cpp:1754:33: warning: Condition 'settings' is always true [knownConditionTrueFalse]
const Library * const lib = settings ? &settings->library : nullptr;
^
lib/symboldatabase.cpp:1751:9: note: Assuming that condition '!settings' is not redundant
if (!settings)
^
lib/symboldatabase.cpp:1754:33: note: Condition 'settings' is always true
const Library * const lib = settings ? &settings->library : nullptr;
```
* Compile parseClangAstDump
2020-01-05 21:10:48 +01:00
Daniel Marjamäki
07cc3e47c4
cppcheck.vcxproj: Try to make appveyor happy
2020-01-05 19:34:25 +01:00
Daniel Marjamäki
0b765cd253
Clang importing; Use ValueFlow
2020-01-05 19:21:13 +01:00
Daniel Marjamäki
fa727185e5
Clang import; IfStmt
2020-01-05 19:18:32 +01:00
amai2012
b621c35539
Astyle formatting [ci skip]
2020-01-05 17:00:34 +01:00
Daniel Marjamäki
211af1d4fe
Clang import: debug output
2020-01-05 16:58:13 +01:00
Paul Fultz II
90f82d0374
Fix issue 9541: false negative: knownConditionTrueFalse ( #2473 )
...
* Fix issue 9541: false negative: knownConditionTrueFalse
* Add another test case
* Add another test
* Fix FPs
* Format
* Fix compile error
* Remove double conditions
* Fix compile error
2020-01-05 16:25:33 +01:00
Ken-Patrick Lehrmann
5f73e1cb32
Fix 9546: properly check that the bound is the size ( #2475 )
...
Previously, as the check was done on the token and not on the ast,
`i <= v.size()` and `i <= v.size() - 2` would both raise the same
warning.
This patch fixes this, but this mean the check is only done when the
condition if `i <= v.size()`. Any other (more complex) condition is
ignore, and so we have false negative for instance with
`i <= v.size() + 1`.
2020-01-05 16:24:25 +01:00
Daniel Marjamäki
bc17b9a1be
Importing Clang ast dump: Run ValueFlow analysis
2020-01-05 16:23:02 +01:00
Daniel Marjamäki
b03bdfaf72
Import Clang ast dump (experimental)
2020-01-05 15:12:53 +01:00
Maksim Derbasov
a3ed9116e5
Clarify error msg for hidingInheritedPublic ( #2474 )
2020-01-05 09:32:39 +01:00
Daniel Marjamäki
4f1e8bc5e7
astyle formatting
...
[ci skip]
2020-01-04 18:47:05 +01:00
Paul Fultz II
e1a97c524d
Fix issue 9554: False positive: The address of local variable 'x' is accessed at non-zero index. ( #2470 )
...
* Fix issue 9554: False positive: The address of local variable 'x' is accessed at non-zero index.
* Format
* Remove unnecesary condition check
2020-01-04 11:39:52 +01:00
Ken-Patrick Lehrmann
a9d423eef2
Fix #8938 : FP identicalInnerCondition ( #2471 )
2020-01-04 11:38:56 +01:00
Ken-Patrick Lehrmann
eca7ee9260
9356: Prevent false positive when passing non-const reference to member constructor ( #2370 )
...
* Add cases for 9356
* 9356: Prevent false positive when passing non-const reference to member constructor
This workarounds false positives 'Parameter can be declared with const [constParameter]'
when said parameter is used in constructor call. It assume the
constructor call might change the parameter (without any checks.
The drawback is that we have false negative, in cases where we could
check the constructor actually takes a const reference, or a copied by
value parameter.
* Add todo comment in isVariableMutableInInitializer
2020-01-04 11:36:45 +01:00
Paul Fultz II
e07801a891
Fix issue 9563: new daca crash: findLambdaEndToken not finding end token ( #2472 )
2020-01-04 10:45:24 +01:00
orbitcowboy
1e0f8ae9b4
Running astyle [ci skip].
2020-01-04 00:06:27 +01:00
Paul Fultz II
dd05839a7e
Fix false positives in knownConditionTrueFalse when using expressions with const variables ( #2469 )
2020-01-03 19:35:28 +01:00
Daniel Marjamäki
0e369edd8c
Verification; Only warn about uninitialized function arguments if VERIFY_UNINIT is defined
2020-01-02 06:16:36 +01:00
Daniel Marjamäki
e32c01b13c
Verification; printing debug output on std::cout
2020-01-01 19:57:49 +01:00
Maksim Derbasov
fc5fd3c40c
Check that virtual function non-narrow access modifier in derived class ( #2229 )
...
* Check that virtual function has not narrowed access in derived class
* motivation info added
* error reporting moved to func
* added suppression for CI
2020-01-01 16:09:43 +01:00
Rikard Falkeborn
7514544d94
Fix #8758 (add syntax error for invalid code) ( #2466 )
2020-01-01 15:46:09 +01:00
Daniel Marjamäki
f23d880a7e
Verification; use <uninit> configuration
2020-01-01 14:37:20 +01:00
Paul Fultz II
30b9455e89
Fix issue 9556: FP mismatchingContainers: raw pointer comparison ( #2465 )
...
* Fix issue 9556: FP mismatchingContainers: raw pointer comparison
* Formatting
2020-01-01 12:02:21 +01:00
Daniel Marjamäki
b44029cdaa
Refactoring; CWEs should be clarified
2020-01-01 09:09:10 +01:00
Daniel Marjamäki
28c37bb63f
Verification; Clarify error message
2020-01-01 08:36:40 +01:00
Daniel Marjamäki
443e8cfbcf
Verification; avoid false positive for known float value
2020-01-01 08:33:27 +01:00
Daniel Marjamäki
d4ec8075a4
Verification; Fix false positive in while loops
2019-12-31 22:32:16 +01:00
Daniel Marjamäki
043634be27
Verification; Better handling of assignment in while
2019-12-31 20:31:31 +01:00
Daniel Marjamäki
446256a503
Verification; assume non-const pointer argument might point at uninitialized data
2019-12-31 17:51:58 +01:00
Daniel Marjamäki
10010eba95
Verification; Avoid fp for array declaration
2019-12-31 16:50:20 +01:00
Dmitry-Me
1a2b770bfd
Break the loop once a match is found
2019-12-31 18:32:45 +03:00
Dmitry-Me
895910b769
Fixed #7159 (wrong handling of function parameters)
2019-12-31 18:26:12 +03:00
Daniel Marjamäki
f55d72e821
Verification; uninitialized local variable
2019-12-31 14:57:42 +01:00
Daniel Marjamäki
48be067dd1
Verification; Added --verify-diff option
2019-12-31 12:05:08 +01:00
Daniel Marjamäki
3af3219076
Verification; Juliet *_float_* division by zero tests
2019-12-31 09:02:06 +01:00
Paul Fultz II
82c91f9484
Fix issue 9550: False positive: Same iterator is used with containers 'x' that are defined in different scopes ( #2463 )
2019-12-31 08:09:04 +01:00
Daniel Marjamäki
fde86b696d
Verification; Use ValueFlow for improved accuracy
2019-12-31 05:59:06 +01:00
Daniel Marjamäki
3ff31b799c
Verification: Use separate id for floating point division by zero
2019-12-30 19:50:22 +01:00
Daniel Marjamäki
4b5585e75b
Verification; floating point division by zero
2019-12-30 19:47:18 +01:00
Daniel Marjamäki
a60efa6774
Verification; Experimental checking for uninit
2019-12-30 18:55:16 +01:00
Daniel Marjamäki
6ea1875a84
Verification; Ensure assertions for variable type limits are added
2019-12-30 12:53:59 +01:00
Daniel Marjamäki
d247ffb13a
Fix compiler warning
2019-12-29 21:22:20 +01:00
Daniel Marjamäki
29b599b0e5
Verification; callbacks in executeCast
2019-12-29 19:17:36 +01:00
Daniel Marjamäki
9723b28385
Verification; struct pointer member
2019-12-29 18:42:35 +01:00
Daniel Marjamäki
2710a94b4b
Verification; Merged handling of pointers and arrays
2019-12-29 16:26:11 +01:00
Paul Fultz II
75de485c4d
Fix issue 9551: Out-of-bounds in getLifetimeTokens() ( #2461 )
2019-12-29 08:23:58 +01:00
Daniel Marjamäki
d16ea3293e
Verification; Fix testing
2019-12-28 22:09:16 +01:00
Daniel Marjamäki
ab2e87191f
Verification; Avoid crash
2019-12-27 20:27:21 +01:00
Daniel Marjamäki
49ed1a82b4
Verification; save report in custom file
2019-12-27 19:25:06 +01:00
Daniel Marjamäki
4b4f7ea60b
Verification; Updated report
2019-12-27 19:05:22 +01:00
Dmitry-Me
147cf9319f
Restore compilation in gcc-4.6
2019-12-27 18:26:44 +03:00
Daniel Marjamäki
ec4668353d
Verification; Determine argument number properly
2019-12-26 18:32:59 +01:00
Daniel Marjamäki
31bddb6ae0
astyle formatting
...
[ci skip]
2019-12-26 15:48:29 +01:00
Paul Fultz II
ce1fc56e96
Fix issue 6890: ValueFlow: min/max value for variable, after condition ( #2460 )
...
* Set bounds when combining values
* Adust bounds when they are negated
* Try to infer conditional values
* Switch false and true
* Fix checking of conditions
* Fix compare
* Fix remaining tests
* Fix overflows
2019-12-26 15:47:53 +01:00
Daniel Marjamäki
8c652afd6e
Verification: Added IntRange::isLessThan and IntRange::isGreaterThan
2019-12-26 15:39:08 +01:00
Dmitry-Me
678560bf0d
Use "override" keyword in clang ( #2459 )
2019-12-25 18:19:00 +03:00
Paul Fultz II
42d44f02a2
Use lifetime analysis for checking mismatching containers ( #2456 )
...
* Use lifetimes to check for mismatching containers
* Fix error messages
* Format
* Remove unused variables
* Fix configuration and track iterators through algorithms
* Fix iterator value types in qt config
* Fix library issue with QStringList
* Remove unused functions
* Fix cppcheck errors
2019-12-25 09:32:50 +01:00
Daniel Marjamäki
0cd2935dc7
Verification; Verify that function call argument values meet annotations
2019-12-25 09:23:07 +01:00
Daniel Marjamäki
f0ac19514b
Verification: Handle Cppcheck annotations __cppcheck_low__ and __cppcheck_high__
2019-12-24 21:14:14 +01:00
Daniel Marjamäki
755e2d261c
Fixed #9402 (ExprEngine: && and || in condition)
2019-12-24 15:52:02 +01:00
Daniel Marjamäki
747a01f74d
Verification; Check function argument values
2019-12-23 22:10:43 +01:00
Daniel Marjamäki
eb551728a5
Verification; Avoid FP for known values
2019-12-22 21:24:39 +01:00
Daniel Marjamäki
93f10da981
Verification; Detect errors after bailout
2019-12-22 21:03:43 +01:00
PKEuS
8218120fd5
Moved function from .h to .cpp
2019-12-21 11:55:11 +01:00
Daniel Marjamäki
7f110f3ec3
Set version
2019-12-21 11:49:01 +01:00
Daniel Marjamäki
6890757986
Update Copyright year
2019-12-21 11:23:01 +01:00
Daniel Marjamäki
fe23d017f3
Fixed #8419 (False positive accessMoved on int)
2019-12-21 07:39:14 +01:00
Daniel Marjamäki
c2f8fb5603
Fixed #9405 (false positive: (style, inconclusive) Boolean expression 'dqOpen' is used in bitwise operation. Did you mean '&&')
2019-12-20 19:38:30 +01:00
Daniel Marjamäki
33ec78fe6e
Fixed #9036 (false positive: (style) Condition 's.x<127U' is always true)
2019-12-20 19:06:35 +01:00
Daniel Marjamäki
bd83630f2e
Fixed #8990 (False positive: struct member not used (union))
2019-12-20 18:31:55 +01:00
Daniel Marjamäki
252c3a17fa
Fixed #7107 (False positive iterators - using alias for container)
2019-12-20 12:13:26 +01:00
Daniel Marjamäki
9ffb657c1a
Fixed #8597 (False positive - Array index is used before limits check.)
2019-12-20 09:46:01 +01:00
Daniel Marjamäki
02eaf6fa93
Fixed #8998 (False positive uninitStructMember related to reference to member)
2019-12-19 20:18:32 +01:00
Daniel Marjamäki
c84ba10b37
Fixed #8774 (Wrong handling of function with name 'or')
2019-12-19 19:22:39 +01:00
Daniel Marjamäki
2a2fa49098
Thread safety: use std::atomic for global flags
2019-12-19 18:38:22 +01:00
Daniel Marjamäki
235ef0a01e
Fixed #9420 (False positive - redundantInitialization)
2019-12-18 19:39:23 +01:00
IOBYTE
ec4c979cd8
fix daca error: Internal Error: Invalid syntax ( #2452 )
...
* fix daca error: Internal Error: Invalid syntax
* fix cppcheck warnings
2019-12-18 11:48:36 +01:00
Daniel Marjamäki
caab1e61bb
Fixed #9542 (Better error handling for --addon)
2019-12-17 12:00:01 +01:00
Maksim Derbasov
68a67a910e
Remove .dump file after plugins execution ( #2451 )
2019-12-17 08:40:59 +01:00
Dmitry-Me
7d6582c7a5
Resolve C4800 Visual C++ warning
2019-12-16 18:11:12 +03:00
Paul Fultz II
ad352daa08
Fix issue 9535: Syntax Error: AST broken, 'if' doesn't have two operands. ( #2450 )
2019-12-16 12:17:01 +01:00
Daniel Marjamäki
a241be0ecc
Fixed #9434 (False positive: Out of bounds access when using const pointer)
2019-12-15 20:10:28 +01:00
Daniel Marjamäki
36f369473e
isPointerDeref: Return false for function declarations
2019-12-15 16:36:46 +01:00
Daniel Marjamäki
f614d32d6a
Fixed #9519 (Syntax error on valid C++ 'enum {} (a)')
2019-12-15 08:40:04 +01:00
Daniel Marjamäki
bcfc5924fa
Fixed #9532 (False positive: Out of bounds access in expression 'v[0]' because 'v' is empty.)
2019-12-14 19:04:19 +01:00
Paul Fultz II
06752d75a5
Fix issue 9485: knownConditionTrueFalse false positive with integer constants ( #2447 )
...
* Fix issue 9485: knownConditionTrueFalse false positive with integer constants
* Formatting
2019-12-14 09:15:00 +01:00
IOBYTE
0e4efea530
fix #9539 (Syntax error for valid C++14 code) ( #2446 )
2019-12-12 20:50:20 +01:00
RobkeBaer
370196a14c
Fix extern c typedef syntax error ( #2438 )
...
* Fix extern c typedef syntax error
* Fix extraWhiteSpaceError
* Move test from testgarbage to testtokenize
2019-12-12 13:51:14 +01:00
orbitcowboy
f89adef1c1
Running astyle [ci skip]
2019-12-11 15:01:21 +01:00
Sebastian
6f2879a59b
errorlogger.cpp: Handle empty file-name like "*" (unmatchedSuppression) ( #2440 )
...
Using "--suppress=unmatchedSuppression" did not suppress the error-id in
all files, one needed to specify "*" as file-name. This commit also
allows empty file-names to suppress "unmatchedSuppression", not only "*"
or the exact file-name.
The manual uses the following example for suppressions specified in a
file:
// suppress all uninitvar errors in all files
uninitvar
This example suggests that no "*" has to be used to get suppression in
all files. I think that the command line parameter should work in the
same way.
2019-12-11 09:07:18 +01:00
Paul Fultz II
ad2f71338c
Fix issue 9525: Syntax Error: AST broken, 'if' doesn't have two operands inside lambda ( #2433 )
...
* Fix issue 9525: Syntax Error: AST broken, 'if' doesn't have two operands inside lambda
* Fix incorrect matchers
2019-12-10 21:21:07 +01:00
Rikard Falkeborn
1c92170179
ValueFlow: Remove unused argument ( #2442 )
2019-12-10 17:48:27 +01:00
Sebastian
95696ead23
Catch preprocessor errors possibly issued during loading files ( #2430 )
...
* Also catch preprocessor errors possibly issued during loading files
Currently only errors that are issued during preprocessing are caught.
* Bump simplecpp, implement suggestions
Use return value checking instead of catching an exception for calling
Preprocessor::loadFiles().
Handle new enum value simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND
where the corresponding enum is used in Cppcheck.
* Use "noloc" location if an explicit include can not be opened
2019-12-09 19:16:55 +01:00
Paul Fultz II
ea2916a3e4
Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands. ( #2429 )
...
* Fix issue 9514: Syntax Error: AST broken, 'for' doesn't have two operands.
* Fix typo
2019-12-07 21:16:25 +01:00
Paul Fultz II
56e17fb228
Fix issue 9524: Syntax Error: AST broken, 'if' doesn't have two operands. ( #2432 )
2019-12-07 21:06:45 +01:00
Sebastian
95e0b0d0f9
Fix #9510 : Crash in valueflow.cpp solveExprValues() (division by zero) ( #2420 )
...
`break` if divider `intval` is 0 to avoid division by 0 as suggested by @pfultz2
Trac ticket: https://trac.cppcheck.net/ticket/9510
2019-12-06 08:08:40 +01:00
IOBYTE
f637d97080
Fix 9509 (Syntax error on empty attribute list) ( #2423 )
2019-12-06 05:17:19 +01:00
Paul Fultz II
2978c67e6f
Fix issue 9511: Syntax Error: AST broken, 'if' doesn't have two operands. ( #2428 )
2019-12-06 04:19:46 +01:00
IOBYTE
5979eec2c0
Fix 9518 (Syntax error on valid C++) ( #2424 )
2019-12-05 20:51:36 +01:00
versat
e712df7cb4
Run astyle [ci skip]
2019-12-04 13:53:10 +01:00
John Marshall
297efcd049
Avoid some additional memleakOnRealloc false positives ( #2422 )
...
* Avoid some additional memleakOnRealloc false positives
checkReallocUsage() already contains code to suppress the
`p = realloc(p, size)` error message when the pointer has been
previously copied from another variable (hence there is an additional
copy of the original pointer value) within the same function, as in
the added realloc21() test case.
Extend this so that `p = *pp` and `p = ptr->foo` are also recognized
as copies from another variable with the same original pointer value,
as in the added realloc22() and realloc23() test cases.
* Rewrite as a single findmatch() expression
2019-12-04 12:13:44 +01:00
Paul Fultz II
36977becba
Fix issue 9196: Lambda confuses check ( #2415 )
2019-12-03 18:30:52 +01:00
amai2012
0e8a145d6c
Run astyle
2019-12-02 22:04:22 +01:00
Paul Fultz II
9cb39b1d7e
Fix issue 9482: False positive: Reference to temporary returned using trailing return type ( #2413 )
2019-12-01 15:10:02 +01:00
Paul Fultz II
2bdb7dc236
Fix issue 9390: valueFlowTerminatingCondition bailout: Skipping function due to incomplete variable NULL ( #2412 )
...
* Fix issue 9390: valueFlowTerminatingCondition bailout: Skipping function due to incomplete variable NULL
* Uncomment keyword
* Add nullptr as well
2019-12-01 15:09:21 +01:00
Paul Fultz II
f77347d7b4
Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr) ( #2411 )
...
* Fix crash 9492: Crash in FwdAnalysis::checkRecursive() (condTok is nullptr)
* Formatting
2019-12-01 14:53:03 +01:00
Paul Fultz II
a71f58ffc2
Fix issue 9441: false positive: new(std::nothrow) and nullPointerRedundantCheck ( #2403 )
...
* Fix issue 9441: false positive: new(std::nothrow) and nullPointerRedundantCheck
* Skip new if it is a variable
2019-12-01 12:16:31 +01:00
Paul Fultz II
79a2e61721
Fix issue 6850: Valueflow: pointer alias, conditional value ( #2402 )
2019-11-30 09:22:03 +01:00
Paul Fultz II
f9d33c07f8
Fix issue 9458: Crash with shadow variables in a lambda ( #2406 )
...
* Fix issue 9458: Crash with shadow variables in a lambda
* Format
2019-11-29 09:45:02 +01:00
IOBYTE
f554a71dea
fix #9495 (Crash when parsing angle brackets in template with type traits (assertion failure)) ( #2407 )
2019-11-29 09:44:27 +01:00
Daniel Marjamäki
676a837af6
Fixed #9335 (FP constStatement "Found a statement that begins with string constant")
2019-11-28 17:49:33 +01:00
Daniel Marjamäki
937c82efbe
AST: initializer list with lambda
2019-11-27 06:44:58 +01:00
Sebastian
c3c3d6770c
Fix #9478 : Valueflow: printf does not change value ( #2388 )
...
Format-string arguments are now marked to have `in` direction, except
for `scan`-functions (like `scanf`) where these arguments are explicitly
marked to have `out` direction.
2019-11-24 01:40:31 +01:00
Daniel Marjamäki
ab2274b8ad
AST: lambdas and scopes in expressions
2019-11-23 21:36:36 +01:00
Daniel Marjamäki
ebd32cfd73
Syntax error: if (retval==)
2019-11-23 18:50:46 +01:00
IOBYTE
fb1d60bfb1
fix syntax error for num.operator std::string()[0] ( #2389 )
2019-11-23 17:42:24 +01:00
Dmitry-Me
b3ed9f8231
Make iterator checks useful
2019-11-21 18:15:26 +03:00
IOBYTE
df952926f8
fix syntax error for a.operator++() ? a.operator--() : 0 ( #2382 )
2019-11-20 22:13:32 +01:00
Dmitry-Me
28ef31c981
Fix "one past end" illegal iterator computation
2019-11-20 18:10:05 +03:00
Sebastian
c990d10ffa
Check for JSON error when parsing addon .json files + fixes ( #2374 )
...
* cppcheck.cpp: Check for JSON error when parsing addon .json files
This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().
* naming.json: Fix missing comma
* CLI: Fix naming violations detected by addon naming.py via naming.json
* Addon naming: Add argument for validating names of constants
* LIB: Rename functions/variables so they are valid, loosen naming rules
* GUI: Fix naming violations
2019-11-20 15:37:09 +01:00
IOBYTE
590aeea8f8
Fix #9483 (Assertion `tok && tok->str() == ">"' failed) ( #2381 )
2019-11-20 07:02:25 +01:00
Paul Fultz II
479fbb85a2
Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency. ( #2376 )
...
* Improve nested init lists
* Fix issue 9443: Internal error: Token::astOperand2() cyclic dependency.
2019-11-19 11:38:03 +01:00
Paul Fultz II
ed1acc319d
Fixx issue 9355: FP constParameter when returning non-const reference to struct member ( #2373 )
2019-11-18 06:39:50 +01:00
IOBYTE
7f6ebaa6b2
fix syntax error for VTK_LEGACY_BODY(vtkMatrix3x3::operator[], "VTK 7.0"); ( #2372 )
2019-11-18 06:38:53 +01:00
Daniel Marjamäki
1d441f64c1
CheckUnusedVar: Quick heuristic so we don't bailout for 'auto' variables
2019-11-17 15:44:57 +01:00
Daniel Marjamäki
d0daf1f90d
CheckUnusedVar: Assume that assignment has 'standard behavior' by default
2019-11-17 12:33:26 +01:00
Daniel Marjamäki
f5e3dc9a38
Improved fix for #8978 (False positive: Variable assigned value that is never used when assigning via iterator)
2019-11-17 12:08:21 +01:00
Paul Fultz II
4ebf54d090
Fix issue 9437: Dont assume init list constructor for strings ( #2366 )
...
* Fix issue 9437: Dont assume init list constuctor for strings
* Update the schema
* Add documentation
2019-11-17 03:22:04 +01:00
Daniel Marjamäki
5654630099
Fixed #8978 (False positive: Variable assigned value that is never used when assigning via iterator)
2019-11-16 19:49:54 +01:00
Daniel Marjamäki
7cd7aff60a
Fixed #9285 (Misleading warning message)
2019-11-16 17:24:54 +01:00
Daniel Marjamäki
bae4faa786
Fixed #9422 (FP uninitdata - writing pointer to output stream)
2019-11-16 11:47:57 +01:00
Daniel Marjamäki
7f57c980f0
Refactoring; shorter code
2019-11-16 11:20:26 +01:00
IOBYTE
754c1fff66
fix syntax error for conversion operator for type with global namespace ( #2365 )
...
* fix syntax error for conversion operator for type with global namespace
* fix syntax error when taking address of operator function
* fix syntax error for using ::operator "" _a;
* fix syntax error for template<> void operator "" _h<'a', 'b', 'c'>() {}
* fix syntax error for operator in parentheses
2019-11-16 08:03:13 +01:00
Daniel Marjamäki
b9835fd4f9
Fixed #9445 (Syntax error on typeof word in C)
2019-11-15 21:20:57 +01:00
IOBYTE
3a617fa04a
Fix #9472 (Syntax error on valid C++ code) ( #2363 )
...
There are probably a lot more valid code patterns that generates syntax
errors so I added "operator" to the error message to make it easier to
find them.
2019-11-15 07:03:57 +01:00
Daniel Marjamäki
7e0fc4fb00
Tokenizer: Detect more syntax errors when operator does not have operands
2019-11-14 21:18:31 +01:00
IOBYTE
2eb575d990
Fix #9468 (Syntax error on valid C++) ( #2358 )
2019-11-14 09:26:21 +01:00
IOBYTE
f88ae21d8f
Fix #9467 (False positive on local variable when template specialization is used) ( #2357 )
2019-11-13 21:34:27 +01:00
Paul Fultz II
7841430793
Fix issue 9428: FP uninitvar for pointer passed to sscanf ( #2344 )
...
* Add indirect to library cfg files
* Check indirect for non null arguments
* Reenable subfunction analysis
* Use indirect 1 when using not-null
* Parse correct string name
* Update documentation
* Make attribute optional
2019-11-13 12:46:54 +01:00
Daniel Marjamäki
49d6bfbd7b
Fixed crash in harfbuzz found by daca@home
2019-11-12 18:22:11 +01:00
Daniel Marjamäki
f5a6aa530d
Fixed #9417 (FP uninitvar - member initialized in operator())
2019-11-11 15:00:53 +01:00
Rikard Falkeborn
38dea4719b
Fix #9166 (print proper types in invalidCast message) ( #2347 )
...
* Fix #9166 (print proper types in invalidCast message)
* Use ValueType->str()
* astyle
* Set default sign to avoid issues on different platforms
2019-11-11 07:17:50 +01:00
Daniel Marjamäki
eaa5bfcadd
Remove 'unsafeClassDivZero' warning. The software verification will cover this better.
2019-11-10 16:49:34 +01:00
Daniel Marjamäki
fcc5fad3ed
Fixed #9113 (false positive: (error) Buffer is accessed out of bounds)
2019-11-10 16:42:48 +01:00
Paul Fultz II
6f29e299fc
Fix issue 9439: false positive: unique_ptr and nullPointerRedundantCheck ( #2346 )
2019-11-10 09:44:59 +01:00
Paul Fultz II
c1da6c7dd2
Fix issue 9461: False positive: Reference to temporary returned using trailing return type ( #2345 )
2019-11-10 09:44:04 +01:00
IOBYTE
0fed6f0091
fix clang testsuite crash ( #2341 )
2019-11-09 18:00:21 +01:00
Daniel Marjamäki
81fff2edf1
Fixed #9464 (Import compile database; only check given configuration)
2019-11-09 17:51:42 +01:00
Paul Fultz II
c75bbbe253
Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x ( #2322 )
...
* Fix issue 9404: False positive: Either the condition 'if(x)' is redundant or there is possible null pointer dereference: a->x
* Use simpleMatch
* Add a test case for the FP
* Check if expression is changed
* Check for no return scope
* Use simpleMatch
2019-11-08 08:11:41 +01:00
Rikard Falkeborn
1fcbd696be
Token::ConcatStr(): Handle mixed string literals ( #2337 )
...
Improve handling of adjacent string literals of different types.
Example of adjacent string literals: "ab" L"cd".
In C89, C++98 and C++03, this is undefined. As of C99 and C++11, this is
well defined and the two string literals are concatenated to L"abcd".
C11 and C++11 introduces the utf16, utf32 and (C++ only) utf8 string
types. Concatenating any of these with a regular c-string works exactely
as the wide string example above. The result of having two adjacent
string literals with different prefix is implementation defined, unless
one is an UTF-8 string literal and the other is a wide string literal.
In this case the behaviour is undefined.
Ignore the undefined and ill-formed programs (this behaviour is unchanged)
and make sure that concatenating a plain c string literal with a prefixed
one works correct (in C99 and C++11 and later versions). It also makes the
behaviour consistent since previously, "ab" L"cd" would result in "abcd"
while L"ab" "cd" would result in L"abcd".
It also means the somewhat awkward updatePropertiesConcatStr() test can
be removed since the added tests would not work if update_properties()
was not called in concatStr().
Since the prefix is stored in the token, testing the type of the string
is not relevant in TestSimplifyTokens. It is tested extensively in
TestToken::stringTypes().
2019-11-08 08:03:45 +01:00
Paul Fultz II
2e955d0f22
Fix issue 9453: False positive: danglingLifetime, address of array argument ( #2335 )
2019-11-07 09:33:17 +01:00
Paul Fultz II
d1f225b8ee
Fix issue 9201: FP: returnDanglingLifetime on pointer to variable of static struct ( #2303 )
...
* Fix issue 9201: FP: returnDanglingLifetime on pointer to variable of static struct
* Fix capture of non-local variables in lambdas
2019-11-05 07:10:32 +01:00
Paul Fultz II
c61880c457
Search relative path first before install path ( #2328 )
2019-11-05 07:09:59 +01:00
Daniel Marjamäki
06ea1a2b53
Fixed #9312 (FP : variable is assigned a value that is never used (static))
2019-11-04 17:59:16 +01:00
Paul Fultz II
acd2a92efc
Fix issue 9395 and 9423: False positive: nullPointerRedundantCheck ( #2323 )
2019-11-04 07:02:25 +01:00
Paul Fultz II
c38bbb75e4
Fix issue 9448: Check for temporaries from library function calls ( #2312 )
2019-11-03 22:02:10 +01:00
Daniel Marjamäki
c7a23f126f
Fixed #9373 (False Positive - missingOverride)
2019-11-03 18:42:04 +01:00
Daniel Marjamäki
c3ae028a41
Fixed #8617 (False positive: uninitdata for memory allocated and initialized in function called new (C code))
2019-11-03 17:08:28 +01:00
Daniel Marjamäki
8c8952ae7c
Fixed #9324 (FP compareBoolExpressionWithInt - when using C++ and/or operator synonyms)
2019-11-03 12:53:30 +01:00
Daniel Marjamäki
03ae0ccef3
AST: Do not hang for code 'foo({ for (a;b;c) {} });'
2019-11-03 11:02:59 +01:00
Daniel Marjamäki
791242ea78
Fixed #6975 and #9376 (Tokenizer: unknown macro without semicolon)
2019-11-02 19:34:19 +01:00
Daniel Marjamäki
28182084f2
Fix crash when there are too many nested scopes. Bail out after 1000 nested scopes. The crash was in gcc and was seen with daca@home.
2019-11-02 18:23:10 +01:00
Dmitry-Me
f2cf71f6e9
Fix typo
2019-11-01 18:39:53 +03:00
IOBYTE
3f0ef01154
Fix #9446 (Syntax error on valid C++ code) ( #2316 )
2019-11-01 09:11:29 +01:00
Daniel Marjamäki
35d04cd2d3
AST: non-standard handling of ; in argument list for unknown macro
2019-11-01 09:05:45 +01:00
Daniel Marjamäki
6e9d496ab3
ValueFlow: handling of char literal size before ValueType has been set
2019-10-31 14:06:46 +01:00
versat
181e1baa69
cppcheck.vcxproj.filters: Also update this Visual Studio file
...
This .filters file has been automatically updated by Visual Studio when
the two new files were added. So it should also be updated.
2019-10-31 09:05:58 +01:00
Daniel Marjamäki
9094ff01d3
Fixed #9363 (knownConditionTrueFalse: False positive about function parameter)
2019-10-31 08:34:09 +01:00
versat
470f0cdfe3
lib/cppcheck.vcxproj: Fix Visual Studio build, add new files.
2019-10-31 08:29:19 +01:00
Daniel Marjamäki
6d1c84e3a6
Fixed #9449 (SymbolDatabase: Function lookup fails when string literal is converted to bool)
2019-10-30 21:05:42 +01:00
Daniel Marjamäki
b96a347914
Tokenizer: Report unknown macro when argument list contains if/for/while/switch
2019-10-30 19:36:19 +01:00
Daniel Marjamäki
33d43808f7
Run dmake
2019-10-30 18:38:37 +01:00
Daniel Marjamäki
8c591308cb
astyle formatting
...
[ci skip]
2019-10-30 18:19:45 +01:00
Paul Fultz II
694d147097
Refactor ProgramMemory and PathAnalysis ( #2311 )
...
* Traverse conditions for container size
* Move program memory to seperate file
* Revert "Traverse conditions for container size"
This reverts commit 914783769f
.
* Move pathanalysis to seperate files
2019-10-30 17:57:46 +01:00
Rikard Falkeborn
239b660a52
Fix #9438 (Don't warn for return (void*) malloc(1)) ( #2307 )
2019-10-30 17:55:47 +01:00
Daniel Marjamäki
277c59e5f3
AST: Fixed AST for lambda that returns template type
2019-10-30 16:05:34 +01:00
IOBYTE
02e7f4f61c
Fix template templates where the template template parameter is not the first parameter. ( #2309 )
2019-10-30 12:12:47 +01:00
Daniel Marjamäki
210232d35c
Fixed #9314 (false positive: (error) Uninitialized variable: ret)
2019-10-29 20:36:58 +01:00
cyy
cf5dd48994
add override ( #2305 )
2019-10-29 20:06:40 +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
c3c9559bee
Fix Cppcheck warning
2019-10-27 18:22:47 +01:00
Daniel Marjamäki
c899d7becf
--verify: Fix false negative in itc
2019-10-27 16:47:56 +01:00
Daniel Marjamäki
2fa9a29ea7
--verify: Fix false negative in itc test suite
2019-10-27 16:40:16 +01:00
Daniel Marjamäki
83a7987f6f
--verify: Fix false negative in itc test suite
2019-10-27 16:23:37 +01:00
Daniel Marjamäki
c56a45840a
Verify: Fix false negative in itc
2019-10-27 15:35:04 +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
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
8cfc833381
ExprEngine: Better handling of container arguments
2019-10-23 22:04:48 +02:00
Daniel Marjamäki
dedee2b173
SymbolDatabase: Better ValueType handling for containers
2019-10-23 19:54:59 +02:00
Daniel Marjamäki
052c02f8ee
ExprEngine: Refactoring
2019-10-23 18:42:40 +02:00
Daniel Marjamäki
bcfc0d32fe
ExprEngine: ::
2019-10-23 18:23:25 +02:00
Daniel Marjamäki
7b50b76b89
ExprEngine: container value
2019-10-23 18:06:10 +02:00
Daniel Marjamäki
4d218d1b47
ExprEngine: Clarify output
2019-10-23 16:40:49 +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
Daniel Marjamäki
3699227b12
ExprEngine: Throw exception if there is unhandled expression in assignment LHS
2019-10-22 18:39:59 +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
Daniel Marjamäki
574141a492
shadowVariable: Add comment
2019-10-19 18:51:36 +02:00
Daniel Marjamäki
24db81adb5
Fixed #8903 (False positive 'shadows outer variable' when using GCC statement expressions)
2019-10-19 18:50:27 +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
Daniel Marjamäki
3a0a0fdefb
Fixed #9424 (False positive: known condition after function call)
2019-10-18 08:21:07 +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
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
Daniel Marjamäki
4a4b4963cc
SymbolDatabase: Fix function lookup for '::func()'
2019-10-15 12:39:02 +02:00
Daniel Marjamäki
d98ac017f7
ExprEngine: Improved handling of struct member assignments in loops
2019-10-14 22:04:12 +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
Daniel Marjamäki
ee280a94fb
ExprEngine: New handling of << and >>
2019-10-14 17:20:35 +02:00