Skip to content

Commit 373075e

Browse files
committed
CPP: Extend the test.
1 parent 0a0bcdf commit 373075e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| test.cpp:13:19:13:29 | charPointer | This pointer might have type $@ (size 4), but the pointer arithmetic here is done with type char * (size 1). | test.cpp:10:31:10:38 | test.cpp:10:31:10:38 | int |
22
| test.cpp:77:17:77:17 | x | This pointer might have type $@ (size 4), but the pointer arithmetic here is done with type char * (size 1). | test.cpp:72:19:72:19 | test.cpp:72:19:72:19 | int |
33
| test.cpp:119:26:119:26 | p | This pointer might have type $@ (size 8), but the pointer arithmetic here is done with type char * (size 1). | test.cpp:114:22:114:22 | test.cpp:114:22:114:22 | mystruct |
4+
| test.cpp:147:19:147:29 | charPointer | This pointer might have type $@ (size 8), but the pointer arithmetic here is done with type char * (size 1). | test.cpp:145:31:145:38 | test.cpp:145:31:145:38 | int[2] |

cpp/ql/test/query-tests/Security/CWE/CWE-468/semmle/IncorrectPointerScaling/test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,10 @@ void* test17(int* x) {
139139
// BAD: void pointer arithmetic is not portable across compilers
140140
return (void*)x + sizeof(int);
141141
}
142+
143+
int test18(int i) {
144+
int intArray[2][2] = { {1, 2}, {3, 4} };
145+
char *charPointer = (char *)intArray;
146+
// BAD: the pointer arithmetic uses type char*, so the offset is not scaled by sizeof(int).
147+
return *(int *)(charPointer + i);
148+
}

0 commit comments

Comments
 (0)