diff options
| author | Anna Zaks <ganna@apple.com> | 2012-05-07 23:30:29 +0000 |
|---|---|---|
| committer | Anna Zaks <ganna@apple.com> | 2012-05-07 23:30:29 +0000 |
| commit | 590c7bc12e471c9944e02907d43d07b9db412a79 (patch) | |
| tree | 6f8267c0305593552990f626407fc6f06b0c20d8 /clang/test/Analysis/malloc-sizeof.c | |
| parent | 4ab2e6be388b5df6b21e47a0f5a0e3c5b2f8b9d5 (diff) | |
| download | bcm5719-llvm-590c7bc12e471c9944e02907d43d07b9db412a79.tar.gz bcm5719-llvm-590c7bc12e471c9944e02907d43d07b9db412a79.zip | |
[analyzer]Turn on MallocSizeOfChecker by default; shorten the diagnostic
llvm-svn: 156341
Diffstat (limited to 'clang/test/Analysis/malloc-sizeof.c')
| -rw-r--r-- | clang/test/Analysis/malloc-sizeof.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/clang/test/Analysis/malloc-sizeof.c b/clang/test/Analysis/malloc-sizeof.c index 1665108e2f4..af8600abe5a 100644 --- a/clang/test/Analysis/malloc-sizeof.c +++ b/clang/test/Analysis/malloc-sizeof.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.unix.MallocSizeof -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=unix.MallocSizeof -verify %s #include <stddef.h> @@ -14,22 +14,22 @@ void foo() { int *ip1 = malloc(sizeof(1)); int *ip2 = malloc(4 * sizeof(int)); - long *lp1 = malloc(sizeof(short)); // expected-warning {{Result of 'malloc' is converted to type 'long *', whose pointee type 'long' is incompatible with sizeof operand type 'short'}} - long *lp2 = malloc(5 * sizeof(double)); // expected-warning {{Result of 'malloc' is converted to type 'long *', whose pointee type 'long' is incompatible with sizeof operand type 'double'}} - long *lp3 = malloc(5 * sizeof(char) + 2); // expected-warning {{Result of 'malloc' is converted to type 'long *', whose pointee type 'long' is incompatible with sizeof operand type 'char'}} + long *lp1 = malloc(sizeof(short)); // expected-warning {{Result of 'malloc' is converted to a pointer of type 'long', which is incompatible with sizeof operand type 'short'}} + long *lp2 = malloc(5 * sizeof(double)); // expected-warning {{Result of 'malloc' is converted to a pointer of type 'long', which is incompatible with sizeof operand type 'double'}} + long *lp3 = malloc(5 * sizeof(char) + 2); // expected-warning {{Result of 'malloc' is converted to a pointer of type 'long', which is incompatible with sizeof operand type 'char'}} struct A *ap1 = calloc(1, sizeof(struct A)); struct A *ap2 = calloc(2, sizeof(*ap1)); - struct A *ap3 = calloc(2, sizeof(ap1)); // expected-warning {{Result of 'calloc' is converted to type 'struct A *', whose pointee type 'struct A' is incompatible with sizeof operand type 'struct A *'}} - struct A *ap4 = calloc(3, sizeof(struct A*)); // expected-warning {{Result of 'calloc' is converted to type 'struct A *', whose pointee type 'struct A' is incompatible with sizeof operand type 'struct A *'}} - struct A *ap5 = calloc(4, sizeof(struct B)); // expected-warning {{Result of 'calloc' is converted to type 'struct A *', whose pointee type 'struct A' is incompatible with sizeof operand type 'struct B'}} + struct A *ap3 = calloc(2, sizeof(ap1)); // expected-warning {{Result of 'calloc' is converted to a pointer of type 'struct A', which is incompatible with sizeof operand type 'struct A *'}} + struct A *ap4 = calloc(3, sizeof(struct A*)); // expected-warning {{Result of 'calloc' is converted to a pointer of type 'struct A', which is incompatible with sizeof operand type 'struct A *'}} + struct A *ap5 = calloc(4, sizeof(struct B)); // expected-warning {{Result of 'calloc' is converted to a pointer of type 'struct A', which is incompatible with sizeof operand type 'struct B'}} struct A *ap6 = realloc(ap5, sizeof(struct A)); - struct A *ap7 = realloc(ap5, sizeof(struct B)); // expected-warning {{Result of 'realloc' is converted to type 'struct A *', whose pointee type 'struct A' is incompatible with sizeof operand type 'struct B'}} + struct A *ap7 = realloc(ap5, sizeof(struct B)); // expected-warning {{Result of 'realloc' is converted to a pointer of type 'struct A', which is incompatible with sizeof operand type 'struct B'}} } // Don't warn when the types differ only by constness. void ignore_const() { const char **x = (const char **)malloc(1 * sizeof(char *)); // no-warning - const char ***y = (const char ***)malloc(1 * sizeof(char *)); // expected-warning {{pointee type 'const char **' is incompatible with sizeof operand type 'char *'}} + const char ***y = (const char ***)malloc(1 * sizeof(char *)); // expected-warning {{Result of 'malloc' is converted to a pointer of type 'const char **', which is incompatible with sizeof operand type 'char *'}} free(x); } |

