Zhongxing Xu | c196095 | 2010-06-16 05:38:05 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -analyzer-store region -verify %s |
| 2 | |
| 3 | typedef __typeof__(sizeof(int)) size_t; |
| 4 | typedef struct _IO_FILE FILE; |
Zhongxing Xu | 23d90f9 | 2010-06-18 02:47:46 +0000 | [diff] [blame^] | 5 | #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. */ |
| 8 | extern FILE *fopen(const char *path, const char *mode); |
| 9 | extern size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); |
| 10 | extern int fseek (FILE *__stream, long int __off, int __whence); |
| 11 | extern long int ftell (FILE *__stream); |
| 12 | extern void rewind (FILE *__stream); |
Zhongxing Xu | c196095 | 2010-06-16 05:38:05 +0000 | [diff] [blame] | 13 | |
| 14 | void 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 Xu | 23d90f9 | 2010-06-18 02:47:46 +0000 | [diff] [blame^] | 19 | |
| 20 | void f2(void) { |
| 21 | FILE *p = fopen("foo", "r"); |
| 22 | fseek(p, 1, SEEK_SET); // expected-warning {{Stream pointer might be NULL.}} |
| 23 | } |
| 24 | |
| 25 | void f3(void) { |
| 26 | FILE *p = fopen("foo", "r"); |
| 27 | ftell(p); // expected-warning {{Stream pointer might be NULL.}} |
| 28 | } |
| 29 | |
| 30 | void f4(void) { |
| 31 | FILE *p = fopen("foo", "r"); |
| 32 | rewind(p); // expected-warning {{Stream pointer might be NULL.}} |
| 33 | } |
| 34 | |