From: Guinevere Larsen Date: Tue, 23 Jun 2026 20:15:36 +0000 (-0300) Subject: gdbsupport: Remove some use after move instances X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fbe48242408fb4f307cebd9cf09fb78231abe0b;p=thirdparty%2Fbinutils-gdb.git 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 --- 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); } };