aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
diff options
context:
space:
mode:
authorGabor Marton <gabor.marton@ericsson.com>2020-12-07 16:10:40 +0100
committerGabor Marton <gabor.marton@ericsson.com>2020-12-08 16:58:30 +0100
commitd14c63167315edfc4a4ad91fac9c866c6e0cb67f (patch)
tree1507c16226549c85850113c12455816e8bee4393 /clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
parent1dd24e6ab7a70242edfa4139441bfe7753892b4e (diff)
downloadllvm-d14c63167315edfc4a4ad91fac9c866c6e0cb67f.zip
llvm-d14c63167315edfc4a4ad91fac9c866c6e0cb67f.tar.gz
llvm-d14c63167315edfc4a4ad91fac9c866c6e0cb67f.tar.bz2
[analyzer][StdLibraryFunctionsChecker] Make close and mmap to accept -1 as fd
close: It is quite often that users chose to call close even if the fd is negative. Theoretically, it would be nicer to close only valid fds, but in practice the implementations of close just returns with EBADF in case of a non-valid fd param. So, we can eliminate many false positives if we let close to take -1 as an fd. Other negative values are very unlikely, because open and other fd factories return with -1 in case of failure. mmap: In the case of MAP_ANONYMOUS flag (which is supported e.g. in Linux) the mapping is not backed by any file; its contents are initialized to zero. The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. Consequently, we must allow -1 as the 4th arg. Differential Revision: https://reviews.llvm.org/D92764
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 8a34950..de825b2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -1672,7 +1672,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
addToFunctionSummaryMap("close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
Summary(NoEvalCall)
.ArgConstraint(ArgumentCondition(
- 0, WithinRange, Range(0, IntMax))));
+ 0, WithinRange, Range(-1, IntMax))));
// long fpathconf(int fildes, int name);
addToFunctionSummaryMap("fpathconf",
@@ -1734,7 +1734,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
Summary(NoEvalCall)
.ArgConstraint(ArgumentCondition(1, WithinRange, Range(1, SizeMax)))
.ArgConstraint(
- ArgumentCondition(4, WithinRange, Range(0, IntMax))));
+ ArgumentCondition(4, WithinRange, Range(-1, IntMax))));
Optional<QualType> Off64_tTy = lookupTy("off64_t");
// void *mmap64(void *addr, size_t length, int prot, int flags, int fd,
@@ -1746,7 +1746,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
Summary(NoEvalCall)
.ArgConstraint(ArgumentCondition(1, WithinRange, Range(1, SizeMax)))
.ArgConstraint(
- ArgumentCondition(4, WithinRange, Range(0, IntMax))));
+ ArgumentCondition(4, WithinRange, Range(-1, IntMax))));
// int pipe(int fildes[2]);
addToFunctionSummaryMap(