Skip to content

[clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker #77576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2024
Merged

[clang][analyzer] Fix incorrect range of 'ftell' in the StdLibraryFunctionsChecker #77576

merged 1 commit into from
Jan 11, 2024

Conversation

benshi001
Copy link
Member

@benshi001 benshi001 commented Jan 10, 2024

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

…ctionsChecker

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Jan 10, 2024
@benshi001 benshi001 requested a review from NagyDonat January 10, 2024 10:32
@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2024

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)

Changes

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 --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))));

@benshi001 benshi001 merged commit 66d022f into llvm:main Jan 11, 2024
@benshi001 benshi001 deleted the csa-ftell branch January 11, 2024 01:10
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…ctionsChecker (llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants