mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
[CPP-434] When analyzing overflow, discard any explicit casts.
Use the simple range analysis library to detect which
additions may in fact overflow.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// Test for BadAdditionOverflowCheck.
|
||||
bool checkOverflow1(unsigned short a, unsigned short b) {
|
||||
return (a + b < a); // BAD: a + b is automatically promoted to int.
|
||||
return (a + b < a); // BAD: comparison always false (due to promotion).
|
||||
}
|
||||
|
||||
// Test for BadAdditionOverflowCheck.
|
||||
bool checkOverflow2(unsigned short a, unsigned short b) {
|
||||
return ((unsigned short)(a + b) < a); // BAD: a + b overflow undefined
|
||||
return ((unsigned short)(a + b) < a); // GOOD
|
||||
}
|
||||
|
||||
// Test for PointlessSelfComparison.
|
||||
|
||||
Reference in New Issue
Block a user