1 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -analyzer-checker=alpha.security.MallocOverflow,unix -verify %s
2 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -analyzer-checker=alpha.security.MallocOverflow,unix,optin.portability -DPORTABILITY -verify %s
4 typedef __typeof__(sizeof(int)) size_t;
5 extern void *malloc(size_t);
6 extern void free(void *ptr
);
8 void *malloc(unsigned long s
);
16 static int table_build(struct table
*t
) {
18 t
->nentry
= ((t
->offset_max
>> 2) + 31) / 32;
19 t
->table
= (unsigned *)malloc(sizeof(unsigned) * t
->nentry
); // expected-warning {{the computation of the size of the memory allocation may overflow}}
23 int *p
= malloc(sizeof(int) * n
); // no-warning
29 static int table_build_1(struct table
*t
) {
30 t
->nentry
= (sizeof(struct table
) * 2 + 31) / 32;
31 t
->table
= (unsigned *)malloc(sizeof(unsigned) * t
->nentry
); // no-warning
36 return malloc(n
* 0 * sizeof(int));
38 // expected-warning@-2{{Call to 'malloc' has an allocation size of 0 bytes}}