Skip to content

clang-tidy problem on read non-blocking file descriptor #124474

@dpetrosy

Description

@dpetrosy

Hi!
I found some suspicious behavior of clang-tidy(version 19.1.3). When I call read on the non-blocking file descriptor, it reports [clang-analyzer-unix.BlockInCriticalSection]

Here is some example code:

std::mutex mtx;

void foo()
{
    std::lock_guard<std::mutex> lock(mtx);

    const char *filename = "example.txt";
    int fd = open(filename, O_RDONLY | O_NONBLOCK);

    char buffer[200] = {};
    read(fd, buffer, 199);
    close(fd);
}

int main()
{
    std::thread th(foo);
    th.join();
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions