C++: Fix false positive by computing range of the converted expression.

This commit is contained in:
Mathias Vorreiter Pedersen
2021-05-10 10:12:43 +02:00
parent 7ac7830973
commit c91ed80e6c
3 changed files with 2 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ where
small = rel.getLesserOperand() and
large = rel.getGreaterOperand() and
rel = l.getCondition().getAChild*() and
upperBound(large).log2() > getComparisonSize(small) * 8 and
upperBound(large.getFullyConverted()).log2() > getComparisonSize(small) * 8 and
// Ignore cases where the smaller type is int or larger
// These are still bugs, but you should need a very large string or array to
// trigger them. We will want to disable this for some applications, but it's

View File

@@ -1,4 +1,3 @@
| test3.cpp:2:8:2:53 | ... < ... | Comparison between $@ of type unsigned char and $@ of wider type unsigned int. | test3.cpp:1:36:1:40 | small | small | test3.cpp:2:43:2:52 | ... - ... | ... - ... |
| test.c:4:14:4:18 | ... < ... | Comparison between $@ of type char and $@ of wider type int. | test.c:3:7:3:7 | c | c | test.c:2:17:2:17 | x | x |
| test.c:9:14:9:18 | ... > ... | Comparison between $@ of type char and $@ of wider type int. | test.c:8:7:8:7 | c | c | test.c:7:17:7:17 | x | x |
| test.c:14:14:14:18 | ... < ... | Comparison between $@ of type short and $@ of wider type int. | test.c:13:8:13:8 | s | s | test.c:12:17:12:17 | x | x |

View File

@@ -1,3 +1,3 @@
void test_issue_5850(unsigned char small, unsigned int large1) {
for(; small < static_cast<unsigned char>(large1 - 1); small++) { } // GOOD [FALSE POSITIVE]
for(; small < static_cast<unsigned char>(large1 - 1); small++) { } // GOOD
}