Patchwork [FYI] Hoist assertion in target_stack::unpush

login
register
mail settings
Submitter Tom Tromey
Date Feb. 5, 2019, 1:37 p.m.
Message ID <20190205133738.9896-1-tom@tromey.com>
Download mbox | patch
Permalink /patch/31312/
State New
Headers show

Comments

Tom Tromey - Feb. 5, 2019, 1:37 p.m.
I noticed that target_stack::unpush first uses the target "t", then
later asserts that it is non-NULL:

  strata stratum = t->stratum ();
[...]
  gdb_assert (t != NULL);

This is backwards, though, as the assertion must come first.

gdb/ChangeLog
2019-02-05  Tom Tromey  <tom@tromey.com>

	* target.c (target_stack::unpush): Move assertion earlier.
---
 gdb/ChangeLog | 4 ++++
 gdb/target.c  | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

Patch

diff --git a/gdb/target.c b/gdb/target.c
index c5502ce1791..c1ab07f7608 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -598,14 +598,14 @@  unpush_target (struct target_ops *t)
 bool
 target_stack::unpush (target_ops *t)
 {
+  gdb_assert (t != NULL);
+
   strata stratum = t->stratum ();
 
   if (stratum == dummy_stratum)
     internal_error (__FILE__, __LINE__,
 		    _("Attempt to unpush the dummy target"));
 
-  gdb_assert (t != NULL);
-
   /* Look for the specified target.  Note that a target can only occur
      once in the target stack.  */