Skip to content

Commit da6806d

Browse files
authored
Improve modeling of two functions in StdLibraryFunctionsChecker (#78079)
Improve 'errno' modeling of 'opendir' and 'fdopendir'.
1 parent 12c7d4c commit da6806d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,18 +2792,21 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
27922792
.ArgConstraint(NotNull(ArgNo(2))));
27932793

27942794
// DIR *opendir(const char *name);
2795-
// FIXME: Improve for errno modeling.
27962795
addToFunctionSummaryMap(
27972796
"opendir", Signature(ArgTypes{ConstCharPtrTy}, RetType{DirPtrTy}),
2798-
Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0))));
2797+
Summary(NoEvalCall)
2798+
.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2799+
.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2800+
.ArgConstraint(NotNull(ArgNo(0))));
27992801

28002802
// DIR *fdopendir(int fd);
2801-
// FIXME: Improve for errno modeling.
2802-
addToFunctionSummaryMap("fdopendir",
2803-
Signature(ArgTypes{IntTy}, RetType{DirPtrTy}),
2804-
Summary(NoEvalCall)
2805-
.ArgConstraint(ArgumentCondition(
2806-
0, WithinRange, Range(0, IntMax))));
2803+
addToFunctionSummaryMap(
2804+
"fdopendir", Signature(ArgTypes{IntTy}, RetType{DirPtrTy}),
2805+
Summary(NoEvalCall)
2806+
.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
2807+
.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
2808+
.ArgConstraint(
2809+
ArgumentCondition(0, WithinRange, Range(0, IntMax))));
28072810

28082811
// int isatty(int fildes);
28092812
addToFunctionSummaryMap(

0 commit comments

Comments
 (0)