40 lines · c
1// RUN: %clang_analyze_cc1 -verify -analyzer-checker=core,unix.API -analyzer-output=text %s2 3// Verify that the UnixAPIChecker finds the missing mode value regardless4// of the particular values of these macros, particularly O_CREAT.5#define O_RDONLY 0x20006#define O_WRONLY 0x80007#define O_CREAT 0x00028 9extern int open(const char *path, int flags, ...);10 11void missing_mode_1(const char *path) {12 (void)open(path, O_CREAT); // expected-warning{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}} \13 expected-note{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}}14}15 16extern int some_flag;17 18void missing_mode_2(const char *path) {19 int mode = O_WRONLY;20 if (some_flag) { // expected-note {{Assuming 'some_flag' is not equal to 0}} \21 expected-note {{Taking true branch}}22 mode |= O_CREAT;23 }24 (void)open(path, mode); // expected-warning{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}} \25 expected-note{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}}26}27 28void no_creat(const char* path) {29 int mode = O_RDONLY;30 (void)open(path, mode); // ok31}32 33void mode_is_there(const char *path) {34 int mode = O_WRONLY;35 if (some_flag) {36 mode |= O_CREAT;37 }38 (void)open(path, mode, 0770); // ok39}40