mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
C++: Use 'size_t' explicitly in test.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
void* malloc(unsigned long size);
|
using size_t = decltype(sizeof 0); void* malloc(size_t size);
|
||||||
|
|
||||||
void test1(int size) {
|
void test1(int size) {
|
||||||
char* p = (char*)malloc(size);
|
char* p = (char*)malloc(size);
|
||||||
@@ -215,7 +215,7 @@ void test13(unsigned len, unsigned index) {
|
|||||||
|
|
||||||
bool unknown();
|
bool unknown();
|
||||||
|
|
||||||
void test14(unsigned long n, char *p) {
|
void test14(size_t n, char *p) {
|
||||||
while (unknown()) {
|
while (unknown()) {
|
||||||
n++;
|
n++;
|
||||||
p = (char *)malloc(n);
|
p = (char *)malloc(n);
|
||||||
@@ -706,7 +706,7 @@ void deref(char* q) {
|
|||||||
char x = *q; // $ deref=L714->L705->L706 // BAD
|
char x = *q; // $ deref=L714->L705->L706 // BAD
|
||||||
}
|
}
|
||||||
|
|
||||||
void test35(unsigned long size, char* q)
|
void test35(size_t size, char* q)
|
||||||
{
|
{
|
||||||
char* p = new char[size];
|
char* p = new char[size];
|
||||||
char* end = p + size; // $ alloc=L711
|
char* end = p + size; // $ alloc=L711
|
||||||
@@ -734,10 +734,10 @@ void test36(unsigned size, unsigned n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test37(unsigned long n)
|
void test37(size_t n)
|
||||||
{
|
{
|
||||||
int *p = new int[n];
|
int *p = new int[n];
|
||||||
for (unsigned long i = n; i != 0u; i--)
|
for (size_t i = n; i != 0u; i--)
|
||||||
{
|
{
|
||||||
p[n - i] = 0; // GOOD
|
p[n - i] = 0; // GOOD
|
||||||
}
|
}
|
||||||
@@ -833,8 +833,8 @@ void test7_no_field_flow(int size) {
|
|||||||
test7_callee_no_field_flow(begin, end);
|
test7_callee_no_field_flow(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test15_with_malloc(unsigned long index) {
|
void test15_with_malloc(size_t index) {
|
||||||
unsigned long size = index + 13;
|
size_t size = index + 13;
|
||||||
if(size < index) {
|
if(size < index) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -842,8 +842,8 @@ void test15_with_malloc(unsigned long index) {
|
|||||||
newname[index] = 0; // $ SPURIOUS: alloc=L841 deref=L842 // GOOD [FALSE POSITIVE]
|
newname[index] = 0; // $ SPURIOUS: alloc=L841 deref=L842 // GOOD [FALSE POSITIVE]
|
||||||
}
|
}
|
||||||
|
|
||||||
void test16_with_malloc(unsigned long index) {
|
void test16_with_malloc(size_t index) {
|
||||||
unsigned long size = index + 13;
|
size_t size = index + 13;
|
||||||
if(size >= index) {
|
if(size >= index) {
|
||||||
int* newname = (int*)malloc(size);
|
int* newname = (int*)malloc(size);
|
||||||
newname[index] = 0; // $ SPURIOUS: alloc=L848 deref=L849 // GOOD [FALSE POSITIVE]
|
newname[index] = 0; // $ SPURIOUS: alloc=L848 deref=L849 // GOOD [FALSE POSITIVE]
|
||||||
|
|||||||
Reference in New Issue
Block a user