diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-11-16 18:47:04 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-11-16 18:47:04 +0000 |
commit | 0c27bcfd05aba22e0b5768849c160e1dbac48537 (patch) | |
tree | 12a70a78662994eeb694fce4a226f8a14cf62794 /clang/test/Analysis/unix-fns.c | |
parent | 4d9c9a646b5d5b9ddab069a7530fbc9372c71759 (diff) | |
download | bcm5719-llvm-0c27bcfd05aba22e0b5768849c160e1dbac48537.tar.gz bcm5719-llvm-0c27bcfd05aba22e0b5768849c160e1dbac48537.zip |
Static analyzer: Catch calls to malloc() with
allocation sizes of 0 bytes.
Fixes PR 2899.
llvm-svn: 119364
Diffstat (limited to 'clang/test/Analysis/unix-fns.c')
-rw-r--r-- | clang/test/Analysis/unix-fns.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/test/Analysis/unix-fns.c b/clang/test/Analysis/unix-fns.c index 9d036ac7b5c..e348beb322d 100644 --- a/clang/test/Analysis/unix-fns.c +++ b/clang/test/Analysis/unix-fns.c @@ -8,6 +8,9 @@ struct _opaque_pthread_once_t { typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; typedef __darwin_pthread_once_t pthread_once_t; int pthread_once(pthread_once_t *, void (*)(void)); +typedef long unsigned int __darwin_size_t; +typedef __darwin_size_t size_t; +void *malloc(size_t); typedef void (^dispatch_block_t)(void); typedef long dispatch_once_t; @@ -50,3 +53,17 @@ void test_pthread_once_neg() { static pthread_once_t pred = {0x30B1BCBA, {0}}; pthread_once(&pred, test_pthread_once_aux); // no-warning } + +// PR 2899 - warn of zero-sized allocations to malloc(). +void pr2899() { + char* foo = malloc(0); // expected-warning{{Call to 'malloc' has an allocation size of 0 bytes}} + for (unsigned i = 0; i < 100; i++) { + foo[i] = 0; + } +} +void pr2899_nowarn(size_t size) { + char* foo = malloc(size); // no-warning + for (unsigned i = 0; i < 100; i++) { + foo[i] = 0; + } +} |