1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=debug.ExprInspection \
4 // RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctions \
5 // RUN: -analyzer-checker=apiModeling.Errno \
6 // RUN: -analyzer-checker=alpha.unix.Errno \
7 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true
9 #include "Inputs/errno_var.h"
11 typedef typeof(sizeof(int)) size_t;
12 typedef __typeof(sizeof(int)) off_t
;
13 typedef size_t ssize_t
;
14 ssize_t
send(int sockfd
, const void *buf
, size_t len
, int flags
);
15 off_t
lseek(int fildes
, off_t offset
, int whence
);
17 void clang_analyzer_warnIfReached();
18 void clang_analyzer_eval(int);
20 int unsafe_errno_read(int sock
, void *data
, int data_size
) {
21 if (send(sock
, data
, data_size
, 0) != data_size
) {
23 // expected-warning@-1{{An undefined value may be read from 'errno'}}
30 int errno_lseek(int fildes
, off_t offset
) {
31 off_t result
= lseek(fildes
, offset
, 0);
32 if (result
== (off_t
)-1) {
34 // check if the function is modeled
35 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
38 if (result
!= offset
) {
39 // Not success path (?)
40 // not sure if this is a valid case, allow to check 'errno'
41 if (errno
== 1) { // no warning
44 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
46 if (result
== offset
) {
47 // The checker does not differentiate for this case.
48 // In general case no relation exists between the arg 2 and the returned
49 // value, only for SEEK_SET.
50 if (errno
== 1) { // no warning
53 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}