GeezerVison is showing github.com — Merge pull request #6745 from andersfugmann/handle_overflow_for_upper… · CodingLi/codeql@06b36f7
File tree
Expand file treeCollapse file tree
Open diff view settings
lib/semmle/code/cpp/rangeanalysis test/library-tests/rangeanalysis/SimpleRangeAnalysis
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: cpp/ql/lib/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1549,7 +1549,8 @@ private float getGuardedUpperBound(VariableAccess guardedAccess) { |
1549 | 1549 | // that there is one predecessor, albeit somewhat conservative. |
1550 | 1550 | exists(unique(BasicBlock b | b = def.(BasicBlock).getAPredecessor())) and |
1551 | 1551 | guardedAccess = def.getAUse(v) and |
1552 | | - result = max(float ub | upperBoundFromGuard(guard, guardVa, ub, branch)) |
| 1552 | + result = max(float ub | upperBoundFromGuard(guard, guardVa, ub, branch)) and |
| 1553 | + not convertedExprMightOverflow(guard.getAChild+()) |
1553 | 1554 | ) |
1554 | 1555 | } |
1555 | 1556 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/lowerBound.expected +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
599 | 599 | | test.c:675:7:675:7 | y | -2147483648 | |
600 | 600 | | test.c:684:7:684:7 | x | -2147483648 | |
601 | 601 | | test.c:689:7:689:7 | x | -2147483648 | |
| 602 | +| test.c:696:8:696:8 | x | 2147483647 | |
| 603 | +| test.c:696:12:696:12 | y | 256 | |
| 604 | +| test.c:697:9:697:9 | x | 2147483647 | |
| 605 | +| test.c:698:9:698:9 | y | 256 | |
602 | 606 | | test.cpp:10:7:10:7 | b | -2147483648 | |
603 | 607 | | test.cpp:11:5:11:5 | x | -2147483648 | |
604 | 608 | | test.cpp:13:10:13:10 | x | -2147483648 | |
|
Collapse file
Copy file name to clipboardExpand all lines: cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/test.c +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -689,3 +689,12 @@ void test(int x) { |
689 | 689 | out(x); |
690 | 690 | goto label; |
691 | 691 | } |
| 692 | + |
| 693 | +void test_overflow() { |
| 694 | + const int x = 2147483647; // 2^31-1 |
| 695 | + const int y = 256; |
| 696 | + if ((x + y) <= 512) { |
| 697 | + out(x); |
| 698 | + out(y); |
| 699 | + } |
| 700 | +} |
Collapse file
Copy file name to clipboardExpand all lines: cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/upperBound.expected +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
599 | 599 | | test.c:675:7:675:7 | y | 2147483647 | |
600 | 600 | | test.c:684:7:684:7 | x | 2147483647 | |
601 | 601 | | test.c:689:7:689:7 | x | 15 | |
| 602 | +| test.c:696:8:696:8 | x | 2147483647 | |
| 603 | +| test.c:696:12:696:12 | y | 256 | |
| 604 | +| test.c:697:9:697:9 | x | 2147483647 | |
| 605 | +| test.c:698:9:698:9 | y | 256 | |
602 | 606 | | test.cpp:10:7:10:7 | b | 2147483647 | |
603 | 607 | | test.cpp:11:5:11:5 | x | 2147483647 | |
604 | 608 | | test.cpp:13:10:13:10 | x | 2147483647 | |
|