aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
diff options
context:
space:
mode:
authorBalázs Kéri <balazs.keri@ericsson.com>2024-02-21 09:18:01 +0100
committerGitHub <noreply@github.com>2024-02-21 09:18:01 +0100
commit1246b64faa5eea1553c1c1aad425c31b701fa6ea (patch)
tree8fdd9ea13a06bdfb21e4805800d3d4f28cc28edd /clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
parent7ce1a11f7f436234ce3eaf11c74043937a1ec36b (diff)
downloadllvm-1246b64faa5eea1553c1c1aad425c31b701fa6ea.zip
llvm-1246b64faa5eea1553c1c1aad425c31b701fa6ea.tar.gz
llvm-1246b64faa5eea1553c1c1aad425c31b701fa6ea.tar.bz2
[clang][analyzer] Change modeling of 'fileno' in checkers. (#81842)
Function 'fileno' fails only if invalid pointer is passed, this is a case that is often ignored in source code. The failure case leads to many "false positive" reports when `fileno` returns -1 and this is not checked in the program. Because this, the function is now assumed to not fail (this is assumption that the passed file pointer is correct). The change affects `StdCLibraryFunctionsChecker` and `StreamChecker`.
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 6b8ac26..6cc8867 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2388,12 +2388,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
.ArgConstraint(NotNull(ArgNo(0))));
// int fileno(FILE *stream);
+ // According to POSIX 'fileno' may fail and set 'errno'.
+ // But in Linux it may fail only if the specified file pointer is invalid.
+ // At many places 'fileno' is used without check for failure and a failure
+ // case here would produce a large amount of likely false positive warnings.
+ // To avoid this, we assume here that it does not fail.
addToFunctionSummaryMap(
"fileno", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
Summary(NoEvalCall)
- .Case(ReturnsValidFileDescriptor, ErrnoMustNotBeChecked,
- GenericSuccessMsg)
- .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+ .Case(ReturnsValidFileDescriptor, ErrnoUnchanged, GenericSuccessMsg)
.ArgConstraint(NotNull(ArgNo(0))));
// void rewind(FILE *stream);