1 // RUN: %clang_analyze_cc1 -verify %s -std=gnu99 \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=alpha.core \
4 // RUN: -analyzer-checker=unix \
5 // RUN: -analyzer-checker=alpha.unix
7 #include "Inputs/system-header-simulator.h"
9 typedef __typeof(sizeof(int)) size_t;
10 void *memset(void *__s
, int __c
, size_t __n
);
11 void *malloc(size_t __size
);
12 void free(void *__ptr
);
14 // The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may
15 // also be live roots.
27 int *x
= malloc(sizeof(int));
28 memset(x
, 0, sizeof(int));
29 int n
= 1 / *x
; // expected-warning {{Division by zero}}
34 int *x
= malloc(sizeof(int));
36 int n
= 1 / *x
; // no-warning
40 void testConcreteNull(void) {
42 memset(x
, 0, 1); // expected-warning {{Null pointer passed as 1st argument to memory set function}}
45 void testStackArray(void) {
47 memset(buf
, 0, 1); // no-warning
50 void testHeapSymbol(void) {
51 char *buf
= (char *)malloc(13);
52 memset(buf
, 0, 1); // no-warning
56 void testStackArrayOutOfBound(void) {
59 // expected-warning@-1 {{Memory set function overflows the destination buffer}}
60 // expected-warning@-2 {{'memset' will always overflow; destination buffer has size 1, but size argument is 1024}}
63 void testHeapSymbolOutOfBound(void) {
64 char *buf
= (char *)malloc(1);
66 // expected-warning@-1 {{Memory set function overflows the destination buffer}}
70 void testStackArraySameSize(void) {
72 memset(buf
, 0, sizeof(buf
)); // no-warning
75 void testHeapSymbolSameSize(void) {
76 char *buf
= (char *)malloc(1);
77 memset(buf
, 0, 1); // no-warning