Issue 175136
Summary clang-analyzer-unix.Errno produces false positive with certain uses of getcwd
Labels false-positive
Assignees
Reporter lultimouomo
    clang-tidy 21 produces a false positive clang-analyzer-unix.Errno warning when `errno` is checked after `getcwd` fails, but only if the buffer passed to `getcwd` needs to be casted to `char*`.


```
#include <unistd.h>
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
 std::vector<char> charbuf(2);
    while(1) {
        if (!getcwd(charbuf.data(), charbuf.size() -1)) {
            // No warning here
            if (errno == ERANGE) {
 charbuf.resize(charbuf.size() + 64);
                continue;
 }
        }
        break;
    }
    std::cout << charbuf.data() << std::endl;

    std::vector<unsigned char> ucharbuf(2);
    while(1) {
 if (!getcwd((char*)ucharbuf.data(), ucharbuf.size() -1)) {
 // warning: An undefined value may be read from 'errno' [clang-analyzer-unix.Errno]
            if (errno == ERANGE) {
 ucharbuf.resize(ucharbuf.size() + 64);
                continue;
 }
        }
        break;
    }
    std::cout << (const char*)ucharbuf.data() << std::endl;
    return 0;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to