stream.c revision 0c2e8c87f18e861cb48965784e20b9292fb70b60
1// 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; 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. */ 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); 13 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} 19 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 35void f5(void) { 36 FILE *p = fopen("foo", "r"); 37 if (!p) 38 return; 39 fseek(p, 1, SEEK_SET); // no-warning 40 fseek(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR.}} 41} 42