Skip to content

Commit bec0064

Browse files
authored
Update test.cpp
1 parent 8737c14 commit bec0064

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

  • cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ void* operator new[]( std::size_t count, const std::nothrow_t& tag );
2020
void badNew_0_0()
2121
{
2222
while (true) {
23-
new int[100];
24-
if(!(new int[100]))
23+
new int[100]; // BAD [NOT DETECTED]
24+
if(!(new int[100])) // BAD [NOT DETECTED]
2525
return;
2626
}
2727
}
2828
void badNew_0_1()
2929
{
30-
int * i = new int[100];
30+
int * i = new int[100]; // BAD
3131
if(i == 0)
3232
return;
3333
if(!i)
3434
return;
3535
if(i == NULL)
3636
return;
3737
int * j;
38-
j = new int[100];
38+
j = new int[100]; // BAD
3939
if(j == 0)
4040
return;
4141
if(!j)
@@ -47,10 +47,10 @@ void badNew_1_0()
4747
{
4848
try {
4949
while (true) {
50-
new(std::nothrow) int[100];
51-
int* p = new(std::nothrow) int[100];
50+
new(std::nothrow) int[100]; // BAD
51+
int* p = new(std::nothrow) int[100]; // BAD
5252
int* p1;
53-
p1 = new(std::nothrow) int[100];
53+
p1 = new(std::nothrow) int[100]; // BAD
5454
}
5555
} catch (const exception &){//const std::bad_alloc& e) {
5656
// std::cout << e.what() << '\n';
@@ -59,16 +59,16 @@ void badNew_1_0()
5959
void badNew_1_1()
6060
{
6161
while (true) {
62-
int* p = new(std::nothrow) int[100];
63-
new(std::nothrow) int[100];
62+
int* p = new(std::nothrow) int[100]; // BAD [NOT DETECTED]
63+
new(std::nothrow) int[100]; // BAD [NOT DETECTED]
6464
}
6565
}
6666

6767
void goodNew_0_0()
6868
{
6969
try {
7070
while (true) {
71-
new int[100];
71+
new int[100]; // GOOD
7272
}
7373
} catch (const exception &){//const std::bad_alloc& e) {
7474
// std::cout << e.what() << '\n';
@@ -78,18 +78,18 @@ void goodNew_0_0()
7878
void goodNew_1_0()
7979
{
8080
while (true) {
81-
int* p = new(std::nothrow) int[100];
81+
int* p = new(std::nothrow) int[100]; // GOOD
8282
if (p == nullptr) {
8383
// std::cout << "Allocation returned nullptr\n";
8484
break;
8585
}
8686
int* p1;
87-
p1 = new(std::nothrow) int[100];
87+
p1 = new(std::nothrow) int[100]; // GOOD
8888
if (p1 == nullptr) {
8989
// std::cout << "Allocation returned nullptr\n";
9090
break;
9191
}
92-
if (new(std::nothrow) int[100] == nullptr) {
92+
if (new(std::nothrow) int[100] == nullptr) { // GOOD
9393
// std::cout << "Allocation returned nullptr\n";
9494
break;
9595
}

0 commit comments

Comments
 (0)