Skip to content

Commit d5a48ad

Browse files
committed
CPP: Additional test cases.
1 parent 84f9900 commit d5a48ad

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
1414
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
1515
| SelfRegistering.cpp:25:3:25:24 | ... = ... | Resource side is acquired by class MyOwner but not released anywhere in this class. |
16-
| Variants.cpp:23:3:23:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |
16+
| Variants.cpp:25:3:25:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |
17+
| Variants.cpp:65:3:65:17 | ... = ... | Resource a is acquired by class MyClass6 but not released anywhere in this class. |
18+
| Variants.cpp:66:3:66:36 | ... = ... | Resource b is acquired by class MyClass6 but not released anywhere in this class. |

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// library
33
typedef unsigned int size_t;
44
void *malloc(size_t size);
5+
void *calloc(size_t nmemb, size_t size);
6+
void *realloc(void *ptr, size_t size);
57
void free(void* ptr);
68

79
int *ID(int *x)
@@ -34,3 +36,40 @@ class MyClass4
3436

3537
int *a, *b, *c, *d, *e, *f, *g;
3638
};
39+
40+
class MyClass5
41+
{
42+
public:
43+
MyClass5()
44+
{
45+
a = new int[10]; // GOOD
46+
b = (int *)calloc(10, sizeof(int)); // GOOD
47+
c = (int *)realloc(0, 10 * sizeof(int)); // GOOD
48+
}
49+
50+
~MyClass5()
51+
{
52+
delete [] a;
53+
free(b);
54+
free(c);
55+
}
56+
57+
int *a, *b, *c;
58+
};
59+
60+
class MyClass6
61+
{
62+
public:
63+
MyClass6()
64+
{
65+
a = new int[10]; // BAD
66+
b = (int *)calloc(10, sizeof(int)); // BAD
67+
c = (int *)realloc(0, 10 * sizeof(int)); // BAD [NOT DETECTED]
68+
}
69+
70+
~MyClass6()
71+
{
72+
}
73+
74+
int *a, *b, *c;
75+
};

0 commit comments

Comments
 (0)