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
) {
66 // expected-note{{Taking false branch}}
70 // expected-note{{Value assigned to 'f'}} \
71 // expected-note{{Assuming that 'fileno' fails}}
73 // expected-warning{{The 1st argument to 'dup' is -1 but should be >= 0}} \
74 // expected-note{{The 1st argument to 'dup' is -1 but should be >= 0}}
77 int test_fileno_arg_note(FILE *f1
) {
78 return dup(fileno(f1
)); // \
79 // expected-warning{{The 1st argument to 'dup' is < 0 but should be >= 0}} \
80 // expected-note{{The 1st argument to 'dup' is < 0 but should be >= 0}} \
81 // expected-note{{Assuming that 'fileno' fails}}