diff options
author | Anna Zaks <ganna@apple.com> | 2012-06-08 18:44:43 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-06-08 18:44:43 +0000 |
commit | 2e336ac5ace420470bbb0ff54a94a5484443a44f (patch) | |
tree | 9d2c96652685dde14cad60133aef390a4a0112b7 /test/Analysis/malloc-sizeof.c | |
parent | 6fe6a49c4058211ff4489023c78615ec0266c5ff (diff) |
[analyzer] MallocSizeofChecker false positive: when sizeof is argument
to addition.
We should not to warn in case the malloc size argument is an
addition containing 'sizeof' operator - it is common to use the pattern
to pack values of different sizes into a buffer.
Ex:
uint8_t *buffer = (uint8_t*)malloc(dataSize + sizeof(length));
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158219 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc-sizeof.c')
-rw-r--r-- | test/Analysis/malloc-sizeof.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/test/Analysis/malloc-sizeof.c b/test/Analysis/malloc-sizeof.c index af8600abe5..6eb466ac6a 100644 --- a/test/Analysis/malloc-sizeof.c +++ b/test/Analysis/malloc-sizeof.c @@ -10,13 +10,14 @@ void free(void *ptr); struct A {}; struct B {}; -void foo() { +void foo(unsigned int unsignedInt, unsigned int readSize) { int *ip1 = malloc(sizeof(1)); int *ip2 = malloc(4 * sizeof(int)); 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'}} + char *cp3 = malloc(5 * sizeof(char) + 2); // no warning + unsigned char *buf = malloc(readSize + sizeof(unsignedInt)); // no warning struct A *ap1 = calloc(1, sizeof(struct A)); struct A *ap2 = calloc(2, sizeof(*ap1)); |