Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdbsupport: Remove some use after move instances
@ 2026-06-23 20:21 Guinevere Larsen
  2026-06-23 20:30 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Guinevere Larsen @ 2026-06-23 20:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: Guinevere Larsen

A static analysis tool was ran on GDB and 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.

This patch fixes that small oversight.
---

There was another issue raised, but it was in the unordered_dense
library, which I don't know if I can just change or if I should submit a
PR to the upstream library.

---
 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);
   }
 };
 

base-commit: 717ef05c9c6d5f7a07540df2e79853d04b56f750
-- 
2.54.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdbsupport: Remove some use after move instances
  2026-06-23 20:21 [PATCH] gdbsupport: Remove some use after move instances Guinevere Larsen
@ 2026-06-23 20:30 ` Simon Marchi
  2026-06-24 11:57   ` Guinevere Larsen
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-06-23 20:30 UTC (permalink / raw)
  To: Guinevere Larsen, gdb-patches



On 2026-06-23 16:21, Guinevere Larsen wrote:
> A static analysis tool was ran on GDB and 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.

I think it's useful to name the tool and if possible paste one example of
such warning.  That can help if someone needs to dig into that change
later (or even when reviewing).

But otherwise this LGTM.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdbsupport: Remove some use after move instances
  2026-06-23 20:30 ` Simon Marchi
@ 2026-06-24 11:57   ` Guinevere Larsen
  0 siblings, 0 replies; 3+ messages in thread
From: Guinevere Larsen @ 2026-06-24 11:57 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 6/23/26 5:30 PM, Simon Marchi wrote:
>
> On 2026-06-23 16:21, Guinevere Larsen wrote:
>> A static analysis tool was ran on GDB and 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.
> I think it's useful to name the tool and if possible paste one example of
> such warning.  That can help if someone needs to dig into that change
> later (or even when reviewing).

Right, makes sense. For completeness on the mailing list, the tool was 
Coverity (I think), and the failure 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|   };

> But otherwise this LGTM.
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>
> Simon
>

-- 
Cheers,
Guinevere Larsen
it/its
she/her (deprecated)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-24 11:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-23 20:21 [PATCH] gdbsupport: Remove some use after move instances Guinevere Larsen
2026-06-23 20:30 ` Simon Marchi
2026-06-24 11:57   ` Guinevere Larsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox