Skip to content

Commit ec95224

Browse files
committed
C++: Test strdup with AV Rule 79.
1 parent f27203c commit ec95224

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/AV Rule 79.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
| Variants.cpp:69:3:69:17 | ... = ... | Resource a is acquired by class MyClass6 but not released anywhere in this class. |
2323
| Variants.cpp:70:3:70:36 | ... = ... | Resource b is acquired by class MyClass6 but not released anywhere in this class. |
2424
| Variants.cpp:71:3:71:41 | ... = ... | Resource c is acquired by class MyClass6 but not released anywhere in this class. |
25+
| Variants.cpp:72:3:72:22 | ... = ... | Resource d is acquired by class MyClass6 but not released anywhere in this class. |
2526
| Wrapped.cpp:46:3:46:22 | ... = ... | Resource ptr2 is acquired by class Wrapped2 but not released anywhere in this class. |
2627
| Wrapped.cpp:59:3:59:22 | ... = ... | Resource ptr4 is acquired by class Wrapped2 but not released anywhere in this class. |

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/Variants.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void *malloc(size_t size);
55
void *calloc(size_t nmemb, size_t size);
66
void *realloc(void *ptr, size_t size);
77
void free(void* ptr);
8-
8+
char *strdup(const char *s1);
99

1010
int *ID(int *x)
1111
{
@@ -46,19 +46,19 @@ class MyClass5
4646
a = new int[10]; // GOOD
4747
b = (int *)calloc(10, sizeof(int)); // GOOD
4848
c = (int *)realloc(0, 10 * sizeof(int)); // GOOD
49-
49+
d = strdup("string");
5050
}
5151

5252
~MyClass5()
5353
{
5454
delete [] a;
5555
free(b);
5656
free(c);
57-
57+
free(d);
5858
}
5959

6060
int *a, *b, *c;
61-
61+
char *d;
6262
};
6363

6464
class MyClass6
@@ -69,15 +69,15 @@ class MyClass6
6969
a = new int[10]; // BAD
7070
b = (int *)calloc(10, sizeof(int)); // BAD
7171
c = (int *)realloc(0, 10 * sizeof(int)); // BAD
72-
72+
d = strdup("string"); // BAD
7373
}
7474

7575
~MyClass6()
7676
{
7777
}
7878

7979
int *a, *b, *c;
80-
80+
char *d;
8181
};
8282

8383
class MyClass7

0 commit comments

Comments
 (0)