diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /test/Analysis/malloc.c | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r-- | test/Analysis/malloc.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index e3d92d9..68308fd 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -1,5 +1,7 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.deadcode.UnreachableCode,experimental.core.CastSize,unix.Malloc,debug.ExprInspection -analyzer-store=region -verify %s -#include "system-header-simulator.h" +// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,debug.ExprInspection -analyzer-store=region -verify %s +// REQUIRES: LP64 + +#include "Inputs/system-header-simulator.h" void clang_analyzer_eval(int); @@ -1000,17 +1002,36 @@ void freeButNoMalloc(int *p, int x){ } struct HasPtr { - int *p; + char *p; }; -int* reallocButNoMalloc(struct HasPtr *a, int c, int size) { +char* reallocButNoMalloc(struct HasPtr *a, int c, int size) { int *s; - a->p = (int *)realloc(a->p, size); - if (a->p == 0) - return 0; // expected-warning{{Memory is never released; potential leak}} + char *b = realloc(a->p, size); + char *m = realloc(a->p, size); // expected-warning {{Attempt to free released memory}} return a->p; } +// We should not warn in this case since the caller will presumably free a->p in all cases. +int reallocButNoMallocPR13674(struct HasPtr *a, int c, int size) { + int *s; + char *b = realloc(a->p, size); + if (b == 0) + return -1; + a->p = b; + return 0; +} + +// Test realloc with no visible malloc. +void *test(void *ptr) { + void *newPtr = realloc(ptr, 4); + if (newPtr == 0) { + if (ptr) + free(ptr); // no-warning + } + return newPtr; +} + // ---------------------------------------------------------------------------- // False negatives. |