blob: 86c702d725942d30fd991aecfeb140c994b3697b [file] [log] [blame]
Jordan Rosecd4db5c2014-08-20 16:58:03 +00001// 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
11int open(const char *, int, ...);
12int close(int fildes);
13
14void 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
21void 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}
Jordan Roseba129af2014-08-20 16:58:09 +000028
29void 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
36void 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
43void 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
53void 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
63void 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
70void 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}