1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.API -verify %s 2 3 #ifndef O_RDONLY 4 #define O_RDONLY 0 5 #endif 6 7 #ifndef NULL 8 #define NULL ((void*) 0) 9 #endif 10 11 int open(const char *, int, ...); 12 int close(int fildes); 13 14 void open_1(const char *path) { 15 int fd; 16 fd = open(path, O_RDONLY); // no-warning 17 if (fd > -1) 18 close(fd); 19 } 20 21 void open_2(const char *path) { 22 int fd; 23 int mode = 0x0; 24 fd = open(path, O_RDONLY, mode, NULL); // expected-warning{{Call to 'open' with more than three arguments}} 25 if (fd > -1) 26 close(fd); 27 } 28 29 void open_3(const char *path) { 30 int fd; 31 fd = open(path, O_RDONLY, NULL); // expected-warning{{Third argument to 'open' is not an integer}} 32 if (fd > -1) 33 close(fd); 34 } 35 36 void open_4(const char *path) { 37 int fd; 38 fd = open(path, O_RDONLY, ""); // expected-warning{{Third argument to 'open' is not an integer}} 39 if (fd > -1) 40 close(fd); 41 } 42 43 void open_5(const char *path) { 44 int fd; 45 struct { 46 int val; 47 } st = {0}; 48 fd = open(path, O_RDONLY, st); // expected-warning{{Third argument to 'open' is not an integer}} 49 if (fd > -1) 50 close(fd); 51 } 52 53 void open_6(const char *path) { 54 int fd; 55 struct { 56 int val; 57 } st = {0}; 58 fd = open(path, O_RDONLY, st.val); // no-warning 59 if (fd > -1) 60 close(fd); 61 } 62 63 void open_7(const char *path) { 64 int fd; 65 fd = open(path, O_RDONLY, &open); // expected-warning{{Third argument to 'open' is not an integer}} 66 if (fd > -1) 67 close(fd); 68 } 69 70 void open_8(const char *path) { 71 int fd; 72 fd = open(path, O_RDONLY, 0.0f); // expected-warning{{Third argument to 'open' is not an integer}} 73 if (fd > -1) 74 close(fd); 75 } 76