Skip to content

Commit 2ae342c

Browse files
authored
Merge pull request #14258 from MathiasVP/explicit-size_t
C++: Use `size_t` explicitly in CWE-193 tests
2 parents 7c2df87 + 7ef5971 commit 2ae342c

File tree

1 file changed

+9
-9
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-193

1 file changed

+9
-9
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-193/test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void* malloc(unsigned long size);
1+
using size_t = decltype(sizeof 0); void* malloc(size_t size);
22

33
void test1(int size) {
44
char* p = (char*)malloc(size);
@@ -215,7 +215,7 @@ void test13(unsigned len, unsigned index) {
215215

216216
bool unknown();
217217

218-
void test14(unsigned long n, char *p) {
218+
void test14(size_t n, char *p) {
219219
while (unknown()) {
220220
n++;
221221
p = (char *)malloc(n);
@@ -706,7 +706,7 @@ void deref(char* q) {
706706
char x = *q; // $ deref=L714->L705->L706 // BAD
707707
}
708708

709-
void test35(unsigned long size, char* q)
709+
void test35(size_t size, char* q)
710710
{
711711
char* p = new char[size];
712712
char* end = p + size; // $ alloc=L711
@@ -734,10 +734,10 @@ void test36(unsigned size, unsigned n) {
734734
}
735735
}
736736

737-
void test37(unsigned long n)
737+
void test37(size_t n)
738738
{
739739
int *p = new int[n];
740-
for (unsigned long i = n; i != 0u; i--)
740+
for (size_t i = n; i != 0u; i--)
741741
{
742742
p[n - i] = 0; // GOOD
743743
}
@@ -833,17 +833,17 @@ void test7_no_field_flow(int size) {
833833
test7_callee_no_field_flow(begin, end);
834834
}
835835

836-
void test15_with_malloc(unsigned long index) {
837-
unsigned long size = index + 13;
836+
void test15_with_malloc(size_t index) {
837+
size_t size = index + 13;
838838
if(size < index) {
839839
return;
840840
}
841841
int* newname = (int*)malloc(size);
842842
newname[index] = 0; // $ SPURIOUS: alloc=L841 deref=L842 // GOOD [FALSE POSITIVE]
843843
}
844844

845-
void test16_with_malloc(unsigned long index) {
846-
unsigned long size = index + 13;
845+
void test16_with_malloc(size_t index) {
846+
size_t size = index + 13;
847847
if(size >= index) {
848848
int* newname = (int*)malloc(size);
849849
newname[index] = 0; // $ SPURIOUS: alloc=L848 deref=L849 // GOOD [FALSE POSITIVE]

0 commit comments

Comments
 (0)