1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core,unix.StdCLibraryFunctions \
3 // RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
4 // RUN: -analyzer-output=text
6 #include "Inputs/std-c-library-functions-POSIX.h"
7 #define NULL ((void *)0)
9 char *getenv(const char *);
15 char *env
= getenv("VAR"); // \
16 // expected-note{{Assuming the environment variable does not exist}} \
17 // expected-note{{'env' initialized here}}
20 // expected-warning{{Array access (from variable 'env') results in a null pointer dereference}} \
21 // expected-note {{Array access (from variable 'env') results in a null pointer dereference}}
24 int test_isalpha(int *x
, char c
, char d
) {
27 // expected-note{{Taking true branch}}
29 // expected-note{{Null pointer value stored to 'x'}}
33 // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
34 // expected-note {{Dereference of null pointer (loaded from variable 'x')}}
37 int test_isdigit(int *x
, char c
) {
38 if (!isdigit(c
)) {// \
39 // expected-note{{Taking true branch}}
41 // expected-note{{Null pointer value stored to 'x'}}
45 // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
46 // expected-note {{Dereference of null pointer (loaded from variable 'x')}}
49 int test_islower(int *x
) {
51 // No "Assuming..." note. We aren't assuming anything. We *know*.
52 if (islower(c
)) { // \
53 // expected-note{{Taking true branch}}
55 // expected-note{{Null pointer value stored to 'x'}}
59 // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
60 // expected-note {{Dereference of null pointer (loaded from variable 'x')}}
63 int test_bugpath_notes(FILE *f1
, char c
, FILE *f2
) {
64 // This test has the purpose of checking that notes appear at correct place.
65 long a
= ftell(f2
); // no note
67 // expected-note{{Taking false branch}}
69 int l
= islower(c
); // no note
71 // expected-note{{Value assigned to 'a'}} \
72 // expected-note{{Assuming that 'ftell' fails}}
74 // expected-warning{{The 1st argument to 'dup' is -1 but should be >= 0}} \
75 // expected-note{{The 1st argument to 'dup' is -1 but should be >= 0}}
78 int test_fileno_arg_note(FILE *f1
) {
79 return dup(fileno(f1
)); // no warning
82 int test_readlink_bufsize_zero(char *Buf
, size_t Bufsize
) {
83 ssize_t Ret
= readlink("path", Buf
, Bufsize
); // \
84 // expected-note{{Assuming that argument 'bufsize' is 0}} \
85 // expected-note{{'Ret' initialized here}}
87 // expected-warning{{Division by zero}} \
88 // expected-note{{Division by zero}}