[clang] [clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker (PR #77576)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 10 02:32:39 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ben Shi (benshi001)
<details>
<summary>Changes</summary>
According to https://pubs.opengroup.org/onlinepubs/9699919799/, the return value of 'ftell' is not restricted to > 0, and may return 0 in real world.
And the corresponding unit test also show `Ret >= 0` not `Ret > 0`.
https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/stream-errno.c#L194
---
Full diff: https://github.com/llvm/llvm-project/pull/77576.diff
1 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp (+1-1)
``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 32a2deab871c79..3b36565681a7f3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2274,7 +2274,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
addToFunctionSummaryMap(
"ftell", Signature(ArgTypes{FilePtrTy}, RetType{LongTy}),
Summary(NoEvalCall)
- .Case({ReturnValueCondition(WithinRange, Range(1, LongMax))},
+ .Case({ReturnValueCondition(WithinRange, Range(0, LongMax))},
ErrnoUnchanged, GenericSuccessMsg)
.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
.ArgConstraint(NotNull(ArgNo(0))));
``````````
</details>
https://github.com/llvm/llvm-project/pull/77576
More information about the cfe-commits
mailing list