summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/analyzer/malloc-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/analyzer/malloc-1.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
index 3219f85f721..d69a60530eb 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
@@ -271,23 +271,23 @@ int *test_23a (int n)
int test_24 (void)
{
- void *ptr = __builtin_alloca (sizeof (int)); /* { dg-message "memory is allocated on the stack here" } */
- free (ptr); /* { dg-warning "'free' of memory allocated on the stack by 'alloca' \\('ptr'\\) will corrupt the heap \\\[CWE-590\\\]" } */
+ void *ptr = __builtin_alloca (sizeof (int)); /* { dg-message "region created on stack here" } */
+ free (ptr); /* { dg-warning "'free' of 'ptr' which points to memory on the stack \\\[CWE-590\\\]" } */
}
int test_25 (void)
{
- char tmp[100];
- void *p = tmp; /* { dg-message "pointer is from here" } */
- free (p); /* { dg-warning "'free' of 'p' which points to memory not on the heap \\\[CWE-590\\\]" } */
+ char tmp[100]; /* { dg-message "region created on stack here" } */
+ void *p = tmp;
+ free (p); /* { dg-warning "'free' of 'p' which points to memory on the stack \\\[CWE-590\\\]" } */
/* TODO: more precise messages here. */
}
-char global_buffer[100];
+char global_buffer[100]; /* { dg-message "region created here" } */
int test_26 (void)
{
- void *p = global_buffer; /* { dg-message "pointer is from here" } */
+ void *p = global_buffer;
free (p); /* { dg-warning "'free' of 'p' which points to memory not on the heap \\\[CWE-590\\\]" } */
/* TODO: more precise messages here. */
}
@@ -608,4 +608,22 @@ int test_49 (int i)
return x;
}
+/* Free of function, and of label within function. */
+
+void test_50a (void)
+{
+}
+
+void test_50b (void)
+{
+ free (test_50a); /* { dg-warning "'free' of '&test_50a' which points to memory not on the heap \\\[CWE-590\\\]" } */
+}
+
+void test_50c (void)
+{
+ my_label:
+ free (&&my_label); /* { dg-warning "'free' of '&my_label' which points to memory not on the heap \\\[CWE-590\\\]" } */
+}
+
+
/* { dg-prune-output "\\\[-Wfree-nonheap-object" } */