]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbsupport: Remove some use after move instances
authorGuinevere Larsen <guinevere@redhat.com>
Tue, 23 Jun 2026 20:15:36 +0000 (17:15 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Wed, 24 Jun 2026 12:08:59 +0000 (09:08 -0300)
We ran the Coverity static analysis tool on GDB and it pointed out some
instances of "use after move" in GDB. The instances that could be easily
removed are related to move constructors for exceptions, that were using
the parameter's reason in an assert, when they could instead just use
their own internal "reason" member. One such example is the following:

Error: USE_AFTER_MOVE (CWE-457):
gdb-17.1/gdbsupport/common-exceptions.h:281:7: move: "ex" is moved (indicated by "std::move(ex)").
gdb-17.1/gdbsupport/common-exceptions.h:283:5: use_after_move: "ex" is used after it has been already moved.
 #  281|       : gdb_exception (std::move (ex))
 #  282|     {
 #  283|->     gdb_assert (ex.reason == RETURN_ERROR);
 #  284|     }
 #  285|   };

This patch fixes that small oversight.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdbsupport/common-exceptions.h

index 1f3bc84216eab5aa67730ecb0362df006c2accf7..37c6e94d5a3a30bfe87f87554b8a2dfe2f6eab86 100644 (file)
@@ -297,7 +297,7 @@ struct gdb_exception_error : public gdb_exception
   explicit gdb_exception_error (gdb_exception &&ex) noexcept
     : gdb_exception (std::move (ex))
   {
-    gdb_assert (ex.reason == RETURN_ERROR);
+    gdb_assert (reason == RETURN_ERROR);
   }
 };
 
@@ -312,7 +312,7 @@ struct gdb_exception_quit : public gdb_exception
   explicit gdb_exception_quit (gdb_exception &&ex) noexcept
     : gdb_exception (std::move (ex))
   {
-    gdb_assert (ex.reason == RETURN_QUIT);
+    gdb_assert (reason == RETURN_QUIT);
   }
 };
 
@@ -327,7 +327,7 @@ struct gdb_exception_forced_quit : public gdb_exception
   explicit gdb_exception_forced_quit (gdb_exception &&ex) noexcept
     : gdb_exception (std::move (ex))
   {
-    gdb_assert (ex.reason == RETURN_FORCED_QUIT);
+    gdb_assert (reason == RETURN_FORCED_QUIT);
   }
 };