stream.c revision 23d90f90413ff1efd7e4410d28ae2cab99af1fdb
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 35