[binutils-gdb] gdbsupport: Remove some use after move instances

Guinevere Larsen via Gdb-cvs <[email protected]> Wed, 24 Jun 2026 12:09:24 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7fbe48242408fb4f307cebd9cf09fb78231abe0b

commit 7fbe48242408fb4f307cebd9cf09fb78231abe0b
Author: Guinevere Larsen <[email protected]>
Date:   Tue Jun 23 17:15:36 2026 -0300

    gdbsupport: Remove some use after move instances
    
    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 <[email protected]>

Diff:
---
 gdbsupport/common-exceptions.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h
index 1f3bc84216e..37c6e94d5a3 100644
--- a/gdbsupport/common-exceptions.h
+++ b/gdbsupport/common-exceptions.h
@@ -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);
   }
 };