public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Immad Mir <mir@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2051] analyzer: fix for ICE in sm-fd.cc [PR106551] Date: Mon, 15 Aug 2022 16:52:47 +0000 (GMT) [thread overview] Message-ID: <20220815165247.D63133858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:ed7e7620188dc0e653815bdd40d8802bd5446638 commit r13-2051-ged7e7620188dc0e653815bdd40d8802bd5446638 Author: Immad Mir <mirimmad@outlook.com> Date: Mon Aug 15 22:21:27 2022 +0530 analyzer: fix for ICE in sm-fd.cc [PR106551] This patch fixes the ICE caused by valid_to_unchecked_state in sm-fd.cc by exiting early if first argument of any "dup" functions is invalid. gcc/analyzer/ChangeLog: PR analyzer/106551 * sm-fd.cc (check_for_dup): exit early if first argument is invalid for all dup functions. gcc/testsuite/ChangeLog: PR analyzer/106551 * gcc.dg/analyzer/fd-dup-1.c: New testcase. Signed-off-by: Immad Mir <mirimmad@outlook.com> Diff: --- gcc/analyzer/sm-fd.cc | 3 +-- gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc index e02b86baad1..505d598f3f0 100644 --- a/gcc/analyzer/sm-fd.cc +++ b/gcc/analyzer/sm-fd.cc @@ -976,8 +976,7 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node, { check_for_open_fd (sm_ctxt, node, stmt, call, callee_fndecl, DIRS_READ_WRITE); - if (kind == DUP_1) - return; + return; } switch (kind) { diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c b/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c index b971d31b1c7..b4f43e7f0ef 100644 --- a/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c @@ -245,4 +245,15 @@ test_22 (int flags) close (fd); } +void do_something(); +void +test_23 () +{ + int nullfd = -1; + int fd = 1; + if (dup2 (nullfd, fd) < 0) /* { dg-warning "'dup2' on possibly invalid file descriptor 'nullfd'" } */ + { + do_something(); + } +}
reply other threads:[~2022-08-15 16:52 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220815165247.D63133858D1E@sourceware.org \ --to=mir@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).