]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix for ICE in sm-fd.cc [PR106551]
authorImmad Mir <mirimmad@outlook.com>
Mon, 15 Aug 2022 16:51:27 +0000 (22:21 +0530)
committerImmad Mir <mirimmad@outlook.com>
Mon, 15 Aug 2022 16:51:36 +0000 (22:21 +0530)
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>
gcc/analyzer/sm-fd.cc
gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c

index e02b86baad18a3a2e3729f10558b4cf65830ca47..505d598f3f0b837b94121c188ec6f3913a77e6c1 100644 (file)
@@ -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)
     {
index b971d31b1c77c0d9df7b646dcf8d4780daa3c30d..b4f43e7f0ef788d1ce23f45e5c890d560ca3d1ee 100644 (file)
@@ -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();
+    }
+}