Debian Codegraph @

clang/test/Analysis/issue-124474.cpp

raw
1 // RUN: %clang_analyze_cc1 \
2 // RUN: -analyzer-checker=core,unix.BlockInCriticalSection \
3 // RUN: -analyzer-output text -verify %s
4
5 // expected-no-diagnostics
6
7 #include "Inputs/system-header-simulator-cxx-std-locks.h"
8
9 std::mutex mtx;
10 using ssize_t = long long;
11 using size_t = unsigned long long;
12 int open(const char *__file, int __oflag, ...);
13 ssize_t read(int fd, void *buf, size_t count);
14 void close(int fd);
15 #define O_RDONLY 00
16 #define O_NONBLOCK 04000
17
18 void foo() {
19 std::lock_guard<std::mutex> lock(mtx);
20
21 const char *filename = "example.txt";
22 int fd = open(filename, O_RDONLY | O_NONBLOCK);
23
24 char buffer[200] = {};
25 read(fd, buffer, 199); // no-warning: fd is a non-block file descriptor or equals to -1
26 close(fd);
27 }
28
29 void foo1(int fd) {
30 std::lock_guard<std::mutex> lock(mtx);
31
32 const char *filename = "example.txt";
33 char buffer[200] = {};
34 if (fd == -1)
35 read(fd, buffer, 199); // no-warning: consider file descriptor is a symbol equals to -1
36 close(fd);
37 }