Commit Graph

161 Commits

Author SHA1 Message Date
practicalswift 0a1b3a9d6f Fix typos (#1568) 2019-01-06 17:15:57 +01:00
Daniel Marjamäki 39ceb53578 Comment out code in valueFlowArray. There was too many false positives. 2019-01-02 19:57:11 +01:00
Paul Fultz II 34330b51d1 Fix issue 8905: Condition 'a==0' is always false
This fixes the FP in:

```cpp
void f(const int a[]){ if (a == 0){} }
```
2018-12-18 08:16:43 +01:00
Paul Fultz II 025881cf35 Fix issue 8829: Condition '...' is always true (int buf[42]; if(buf != NULL){})
This makes arrays non-null in valueflow, so it can catch comparisons against null that is always true:

```cpp
void f(void) {
   int buf[42];
   if( buf != 0) {;} // << always true
}
```
2018-12-17 06:07:34 +01:00
Paul Fultz II 5a6f9ac82a Fix FP with strcmp and terminating conditions 2018-11-27 06:39:29 +01:00
Paul Fultz II f0c86b9d14 Fix issue 8842: Crash in valueFlowTerminatingCondition on incomplete code (#1480) 2018-11-14 06:23:45 +01:00
Paul Fultz II e46691597e Fix issue 8841: FP knownConditionTrueFalse - Dont treat unknown function as noreturn (#1474)
* Fix issue 8841: Dont treat unknown function as noreturn

* Add a parameter to set default value when the function is unknown
2018-11-11 08:04:01 +01:00
Paul Fultz II 36e663e250 Fix issue 8839: FP knownConditionTrueFalse - condition inside a while-clause (#1469) 2018-11-09 06:09:51 +01:00
Paul Fultz II 7373be2bfa Add a pass in valueflow for terminating conditions (#1323)
* Add valueflow for terminating conditions

* Add valueflow test

* Dont check for same expressions for now to avoid double diagnostics

* Check nesting

* Add more tests

* Ensure conditions happen in order

* Check for null

* Add error path

* Support same expression check as well

* Use early continue

* Skip checking the same token

* Avoid double condtion diagnosis

* Fix FP when in switch statements

* Fix FP when time function

* Skip conditional escapes

* Use simpleMatch

* Fix naming

* Fix typo
2018-11-07 06:49:07 +01:00
Daniel Marjamäki e53be26f48 Try to fix Travis 2018-11-02 19:04:21 +01:00
Paul Fultz II fafd0742d4 Fix FPs with return conditions (#1455)
* Fix 8815: FP with identical inner conditions

* Fix issue 8801: FP when not returning a bool

* Fix FP

* Add missing semicolon

* Move returnVar
2018-10-31 09:47:48 +01:00
Daniel Marjamäki b8e8b12783 Fixed #8797 (exprDependsOnThis handle method call in non-inline method) 2018-10-24 20:17:00 +02:00
Daniel Marjamäki 2348dcde6c #8801: Quick fix for false positives 2018-10-24 19:57:50 +02:00
Paul Fultz II edde0eedaa Fix FP issue 8801: Condition 'a+b' is always true (#1444) 2018-10-21 08:04:00 +02:00
Daniel Marjamäki 29feaa5a51 Tokenizer: Avoid constant folding 2018-10-20 10:51:50 +02:00
Paul Fultz II 40cb9cb1bc Check conditions in return statements (#1411)
* Identify return conditions in multiconditions

* Improve error messages

* Check return statements are always true or false

* Add more tests for FPs

* Fix FP when returning const like variables

* Fix FP when returning pointers or classes

* Fix FP with member variable access

* Check non-local variables

* Use simplematch

* Check for null
2018-10-18 21:01:47 +02:00
Daniel Marjamäki f961324d45 Fixed #8735 (FP oppositeInnerCondition - regression) 2018-10-07 18:30:29 +02:00
Paul Fultz II e170a45230 Enable followVar for opposite expressions (#1404)
Enable followVar for opposite expressions
2018-10-04 21:17:47 +02:00
Paul Fultz II 1fe1ec09a8 Reenable follow var for logical conjunction (#1400) 2018-10-01 14:40:03 +02:00
Paul Fultz II 2c91b95d2a Reenable followVar for multicondition (#1401) 2018-10-01 14:34:55 +02: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 afe09f4d7a Temporarily comment out the followVariable() handling 2018-09-23 16:03:18 +02:00
Paul Fultz II fa40b821e6 Fix issue 8740: Add a pass to check for valid operators (#1372) 2018-09-08 21:10:34 +02:00
Paul Fultz II cb03b9883f Fix issue 8737: FP with identical inner condition due to followVar (#1371) 2018-09-07 20:16:38 +02:00
Paul Fultz II 5a2362b2a0 Fix issue 8738: Dont warn about multiconditions when value is known (#1369) 2018-09-07 15:02:34 +02:00
Paul Fultz II 2da958efb5 Fix issue 8722: Avoid duplicate messages due for followVar (#1367) 2018-09-06 06:55:36 +02:00
Paul Fultz II 08f301a0de Reenable followVar (#1363)
Reenable followVar
2018-09-05 05:53:33 +02:00
Daniel Marjamäki a331206b44 Temporarily disable followVariableExpressions(), there are problems that should be fixed. 2018-09-01 08:32:06 +02:00
Paul Fultz II fc135e1087 Check if member function modifies the variable (#1350)
* Check if member function modifies the variable

* Check for const pointer

* Add test for const condition

* Add more null checking

* Add todo assert for FN
2018-08-27 11:09:09 +02:00
Paul Fultz II 3947c23290 Fix issue 8369: False negative: Condition 'condition' is always true (#1325)
* Fix issue 8369: False negative: Condition 'condition' is always true

* Use simpleMatch

* Add iterator header

* Cleanup

* Remove unused variable
2018-08-10 18:05:23 +02:00
Paul Fultz II f603b529df Fix issue 8413: Condition is always false 'i=expr; if (i != expr) {}' (#1295)
* Follow variables when comparing same expression

* Remove assert include

* Dont follow function arguments

* Improve the checking to check more cases

* Add more tests

* Check if the variable is used inside a loop

* Follow both variables

* Only skip loops when variable is modified in scope

* Fix FP when followed variable is modified

* Dont follow arrays

* Skip pointer indirection

* Make recursive

* Improve checking more variables

* Fix test with sizeof

* Skip following operators

* Fix test when using sizeof

* Dont check every step

* Use early returns

* Update test to use a loop instead of conditional

* Add static

* Check variables are global

* Check local variables in another scope

* Fix issue with const pointers

* Distinguish between pointer indirection and multiply

* Use simple match

* Prevent crash with uniform initialization

* Use unary op and ast to detect pointer indirection

* Expand error message when expression do not match exactly

* Add errorpath to issameexpression

* Revert "Clarify warning message for 'Same expression on both sides of operator'"

This reverts commit 0e491b41a8.

* Check if the tokens are the same

* Report the operator and not the expressions
2018-08-07 09:32:16 +02:00
Daniel Marjamäki 1b933f4dd1 astyle formatting
[ci skip]
2018-08-05 22:40:21 +02:00
Paul Fultz II b839ad60dd Fix issue 6856: add checks in isOppositeCond when using == and < or > (#1298)
* Fix issue 6856: add checks in isOppositeCond when using == and < or >

* Move tests to testcondition

* Fix some more tests

* Fix test messages

* Remove the float check
2018-08-05 22:39:40 +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
Daniel Marjamäki 77b653bf94 Clarify warnings when char literals are converted to bool in conditions 2018-07-21 18:40:06 +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
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
IOBYTE ce50df8047 Fix override warnings. (#1234) 2018-05-15 16:37:40 +02:00
Paul Fultz II c520735009 Improve checking of size condition against empty to avoid FPs (#1213)
* Improve checking of size condition against empty to avoid FPs

* Add const and todo for reverse conditions
2018-05-11 10:22:06 +02:00
Paul Fultz II e571e598b6 Fix false positive with inner conditions when using pointers (#1195) 2018-04-28 18:56:13 +02:00
Daniel Marjamäki 1b4f4d7130 Fixed #8495 (False positive: boolean result used in bitwise operation when & is overloaded) 2018-04-17 22:14:17 +02:00
PKEuS bbfcccf078 Refactorization: Replace several push_back-sequences by initializer lists 2018-04-09 09:41:24 +02:00
Daniel Marjamäki 795b9f5e0f astyle formatting 2018-04-08 09:25:59 +02:00
Paul Fultz II b85dda77da Add a check for identical inner conditions (#1156) 2018-04-08 08:13:44 +02:00
Paul Fultz II 0c6f184423 Fix false positive for opposite conditions when using different containers (#1143)
* Fix false positive for opposite conditions when using different containers

* Add additional test
2018-04-05 06:43:13 +02:00
Daniel Marjamäki 7e4dba6a7e Updated copyright year 2018-03-31 20:59:09 +02:00
Paul 43be20a824 Check more opposite conditions 2018-03-24 07:58:37 +01:00