blob: f834a6a603c4e1da42c418ba11103411fa7d8381 [file] [log] [blame]
Zhongxing Xuc1960952010-06-16 05:38:05 +00001// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store region -verify %s
2
3typedef __typeof__(sizeof(int)) size_t;
4typedef struct _IO_FILE FILE;
Zhongxing Xu23d90f92010-06-18 02:47:46 +00005#define SEEK_SET 0 /* Seek from beginning of file. */
6#define SEEK_CUR 1 /* Seek from current position. */
7#define SEEK_END 2 /* Seek from end of file. */
8extern FILE *fopen(const char *path, const char *mode);
9extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
10extern int fseek (FILE *__stream, long int __off, int __whence);
11extern long int ftell (FILE *__stream);
12extern void rewind (FILE *__stream);
Zhongxing Xuc1960952010-06-16 05:38:05 +000013
14void f1(void) {
15 FILE *p = fopen("foo", "r");
16 char buf[1024];
17 fread(buf, 1, 1, p); // expected-warning {{Stream pointer might be NULL.}}
18}
Zhongxing Xu23d90f92010-06-18 02:47:46 +000019
20void f2(void) {
21 FILE *p = fopen("foo", "r");
22 fseek(p, 1, SEEK_SET); // expected-warning {{Stream pointer might be NULL.}}
23}
24
25void f3(void) {
26 FILE *p = fopen("foo", "r");
27 ftell(p); // expected-warning {{Stream pointer might be NULL.}}
28}
29
30void f4(void) {
31 FILE *p = fopen("foo", "r");
32 rewind(p); // expected-warning {{Stream pointer might be NULL.}}
33}
34