[all-commits] [llvm/llvm-project] b60fec: [analyzer] Assume the result of 'fopen' can't alia...

Balazs Benics via All-commits all-commits at lists.llvm.org
Tue Jul 23 04:23:19 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b60fec27fd1bbab8c2c7a77b4be7836a1beb326f
      https://github.com/llvm/llvm-project/commit/b60fec27fd1bbab8c2c7a77b4be7836a1beb326f
  Author: Balazs Benics <benicsbalazs at gmail.com>
  Date:   2024-07-23 (Tue, 23 Jul 2024)

  Changed paths:
    M clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
    M clang/test/Analysis/stream.c

  Log Message:
  -----------
  [analyzer] Assume the result of 'fopen' can't alias with 'std{in,out,err}' (#100085)

'fopen' should return a new FILE handle, thus we should assume it can't
alias with commonly used FILE handles, such as with 'stdin', 'stdout' or
'stderr'.

This problem appears in code that handles either some input/output file
with stdin or stdout, as the business logic is basically the same no
matter the stream being used.
However, one would should only close the stream if it was opened via
'fopen'. Consequently, such code usually has a condition like `if (f &&
f != stdout)` to guard the `fclose()` call.

This patch brings this assumption, thus eliminates FPs for not taking
the guarded branch.

CPP-5306



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list