[clang] [clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker (PR #77576)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 10 02:32:07 PST 2024
https://github.com/benshi001 created https://github.com/llvm/llvm-project/pull/77576
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
>From e33d2bce007ac6009870a4dbd5227b62c3d6ba41 Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Wed, 10 Jan 2024 18:28:30 +0800
Subject: [PATCH] [clang][analyzer] Fix incorrect range of 'ftell' in the
StdLibraryFunctionsChecker
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.
---
.../lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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))));
More information about the cfe-commits
mailing list