diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-25 00:20:35 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-25 00:20:35 +0000 |
commit | 381d1bf0eeabccac1ba64909cad73d2ee963897b (patch) | |
tree | 1612c00ace7b1e1c2bfce6429e35964aee0ee34f /test/Analysis/unix-fns.c | |
parent | 85fe6f191572453d1a527d19d1502d7013e9035f (diff) |
Add UnixAPIChecker, a meta checker to include various precondition checks for calls
to various unix/posix functions, e.g. 'open()'.
As a first check, check that when 'open()' is passed 'O_CREAT' that it has
a third argument.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97086 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/unix-fns.c')
-rw-r--r-- | test/Analysis/unix-fns.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/Analysis/unix-fns.c b/test/Analysis/unix-fns.c new file mode 100644 index 0000000000..2bc2efa2d7 --- /dev/null +++ b/test/Analysis/unix-fns.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -analyzer-store=region +// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -analyzer-store=basic + +#include <fcntl.h> + +void test_open(const char *path) { + int fd; + fd = open(path, O_RDONLY); // no-warning + if (!fd) + close(fd); + + fd = open(path, O_CREAT); // expected-warning{{Call to 'open' requires a third argument when the 'O_CREAT' flag is set}} + if (!fd) + close(fd); +} |