[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:
Ziemowit Laski
2019-10-22 15:21:30 -07:00
parent 06f63c5477
commit ad5aa182df
4 changed files with 13 additions and 25 deletions

View File

@@ -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.