Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ee3d7d

Browse files
committed
[CPP-434] Address more comments re .cpp test cases.
1 parent 7204e13 commit 6ee3d7d

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BadAdditionOverflowCheck/SignedOverflowCheck.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool shortShort2(unsigned short n1, unsigned short delta) {
4444

4545
/* Distinguish `varname` from `ptr->varname` and `obj.varname` */
4646
struct N {
47-
unsigned short n1;
47+
int n1;
4848
} n, *np;
4949

5050
bool shortStruct1(unsigned short n1, unsigned short delta) {
@@ -60,7 +60,7 @@ bool shortStruct2(unsigned short n1, unsigned short delta) {
6060
}
6161

6262
struct se {
63-
short xPos;
63+
int xPos;
6464
short yPos;
6565
short xSize;
6666
short ySize;
@@ -70,7 +70,7 @@ extern se *getSo(void);
7070

7171
bool func1(se *so) {
7272
se *o = getSo();
73-
if (so->xPos + so->xSize < o->xPos // GOOD
73+
if (so->xPos + so->xSize < so->xPos // BAD
7474
|| so->xPos > o->xPos + o->xSize) { // GOOD
7575
// clang 8.0.0 -O2: not deleted
7676
// gcc 9.2 -O2: not deleted
@@ -100,9 +100,9 @@ int overflow12(int n) {
100100
}
101101

102102
bool multipleCasts(char x) {
103-
// clang 9.0.0 -O2: deleted
104-
// gcc 9.2 -O2: deleted
105-
// msvc 19.22 /O2: deleted
103+
104+
// BAD [UNDETECTED - BadAdditionOverflowCheck.ql]
105+
// GOOD [SigneOverflowCheck.ql]: Test always fails, but will never overflow.
106106
return (int)(unsigned short)x + 2 < (int)(unsigned short)x; // GOOD: cannot overflow
107107
}
108108

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| SignedOverflowCheck.cpp:8:12:8:22 | ... < ... | Testing for signed overflow may produce undefined results. |
22
| SignedOverflowCheck.cpp:18:12:18:26 | ... < ... | Testing for signed overflow may produce undefined results. |
3+
| SignedOverflowCheck.cpp:73:6:73:36 | ... < ... | Testing for signed overflow may produce undefined results. |
34
| SignedOverflowCheck.cpp:99:10:99:30 | ... <= ... | Testing for signed overflow may produce undefined results. |
45
| SignedOverflowCheck.cpp:122:10:122:42 | ... <= ... | Testing for signed overflow may produce undefined results. |

0 commit comments

Comments
 (0)