"This change adds alloca/valloc checks to UnixAPIChecker. It includes a small refactoring for
the common *alloc functions as well as a few tiny wibbles (adds a note
to CWE/CERT advisory numbers in the bug output, and fixes a couple
80-column-wide violations.)"

Patch by Austin Seipp!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147931 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/unix-fns.c b/test/Analysis/unix-fns.c
index 86b95c6..ec62098 100644
--- a/test/Analysis/unix-fns.c
+++ b/test/Analysis/unix-fns.c
@@ -12,6 +12,8 @@
 void *calloc(size_t, size_t);
 void *malloc(size_t);
 void *realloc(void *, size_t);
+void *alloca(size_t);
+void *valloc(size_t);
 
 typedef void (^dispatch_block_t)(void);
 typedef long dispatch_once_t;
@@ -98,3 +100,39 @@
     foo[i] = 0;
   }
 }
+void test_alloca() {
+  char *foo = alloca(0); // expected-warning{{Call to 'alloca' has an allocation size of 0 bytes}}
+  for(unsigned i = 0; i < 100; i++) {
+    foo[i] = 0; 
+  }
+}
+void test_alloca_nowarn(size_t sz) {
+  char *foo = alloca(sz); // no-warning
+  for(unsigned i = 0; i < 100; i++) {
+    foo[i] = 0;
+  }
+}
+void test_builtin_alloca() {
+  char *foo2 = __builtin_alloca(0); // expected-warning{{Call to 'alloca' has an allocation size of 0 bytes}}
+  for(unsigned i = 0; i < 100; i++) {
+    foo2[i] = 0; 
+  }
+}
+void test_builtin_alloca_nowarn(size_t sz) {
+  char *foo2 = __builtin_alloca(sz); // no-warning
+  for(unsigned i = 0; i < 100; i++) {
+    foo2[i] = 0;
+  }
+}
+void test_valloc() {
+  char *foo = valloc(0); // expected-warning{{Call to 'valloc' has an allocation size of 0 bytes}}
+  for(unsigned i = 0; i < 100; i++) {
+    foo[i] = 0; 
+  }
+}
+void test_valloc_nowarn(size_t sz) {
+  char *foo = valloc(sz); // no-warning
+  for(unsigned i = 0; i < 100; i++) {
+    foo[i] = 0;
+  }
+}