[all-commits] [llvm/llvm-project] d14c63: [analyzer][StdLibraryFunctionsChecker] Make close ...

Gabor Marton via All-commits all-commits at lists.llvm.org
Tue Dec 8 08:01:43 PST 2020


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d14c63167315edfc4a4ad91fac9c866c6e0cb67f
      https://github.com/llvm/llvm-project/commit/d14c63167315edfc4a4ad91fac9c866c6e0cb67f
  Author: Gabor Marton <gabor.marton at ericsson.com>
  Date:   2020-12-08 (Tue, 08 Dec 2020)

  Changed paths:
    M clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list