[clang] Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (PR #77040)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 5 00:57:50 PST 2024
================
@@ -2516,12 +2516,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
.ArgConstraint(NotNull(ArgNo(0))));
// char *getcwd(char *buf, size_t size);
- // FIXME: Improve for errno modeling.
addToFunctionSummaryMap(
"getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
Summary(NoEvalCall)
+ .Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+ ErrnoMustNotBeChecked, GenericSuccessMsg)
+ .Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+ .ArgConstraint(NotNull(ArgNo(0)))
.ArgConstraint(
- ArgumentCondition(1, WithinRange, Range(0, SizeMax))));
+ ArgumentCondition(1, WithinRange, Range(1, SizeMax))));
----------------
balazske wrote:
Here a `BufferSize` type of constraint can be used additionally. See `readlink` for example.
Value 0 is allowed for the size. Passing 0 is not undefined behavior, the function shall fail and set `errno`. A new case can be added (like at `readlink`).
https://github.com/llvm/llvm-project/pull/77040
More information about the cfe-commits
mailing list