CPP: Additional test cases.

This commit is contained in:
Geoffrey White
2018-09-21 15:45:21 +01:00
parent 84f9900c8c
commit d5a48ad63e
2 changed files with 42 additions and 1 deletions

View File

@@ -13,4 +13,6 @@
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
| PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
| SelfRegistering.cpp:25:3:25:24 | ... = ... | Resource side is acquired by class MyOwner but not released anywhere in this class. |
| Variants.cpp:23:3:23:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |
| Variants.cpp:25:3:25:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |
| Variants.cpp:65:3:65:17 | ... = ... | Resource a is acquired by class MyClass6 but not released anywhere in this class. |
| Variants.cpp:66:3:66:36 | ... = ... | Resource b is acquired by class MyClass6 but not released anywhere in this class. |

View File

@@ -2,6 +2,8 @@
// library
typedef unsigned int size_t;
void *malloc(size_t size);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
void free(void* ptr);
int *ID(int *x)
@@ -34,3 +36,40 @@ public:
int *a, *b, *c, *d, *e, *f, *g;
};
class MyClass5
{
public:
MyClass5()
{
a = new int[10]; // GOOD
b = (int *)calloc(10, sizeof(int)); // GOOD
c = (int *)realloc(0, 10 * sizeof(int)); // GOOD
}
~MyClass5()
{
delete [] a;
free(b);
free(c);
}
int *a, *b, *c;
};
class MyClass6
{
public:
MyClass6()
{
a = new int[10]; // BAD
b = (int *)calloc(10, sizeof(int)); // BAD
c = (int *)realloc(0, 10 * sizeof(int)); // BAD [NOT DETECTED]
}
~MyClass6()
{
}
int *a, *b, *c;
};