[clang] [clang][Sema] Add buffer-size checks for unistd I/O functions (PR #224979)
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 8 15:48:32 PDT 2026
================
@@ -1487,6 +1487,66 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
break;
}
+ case Builtin::BIread:
+ case Builtin::BIpread:
+ case Builtin::BIpread64:
+ case Builtin::BIreadlink:
+ case Builtin::BIreadlinkat:
+ case Builtin::BIgetcwd: {
+ unsigned BufIdx = 1;
+ if (BuiltinID == Builtin::BIgetcwd)
+ BufIdx = 0;
+ else if (BuiltinID == Builtin::BIreadlinkat)
+ BufIdx = 2;
----------------
nickdesaulniers wrote:
I think you might better reduce the redundant conditional checks in the case by grouping the builtins into these 3 groupings based on roughly on function signature:
1. read, write, pread, pread64, pwrite, pwrite64: `(int fd, [const] void *buf, size_t count[, off_t offset])`
2. readlink, readlinkat: ([int dirfd, ]const char *path, char *buf, size_t bufsiz)
3. getcwd: (char *buf, size_t size)
i.e. have blocks of case labels for each of the three above.
https://github.com/llvm/llvm-project/pull/224979
More information about the cfe-commits
mailing list