simplify target_is_pushed
authorTom Tromey <tromey@redhat.com>
Fri, 18 Jul 2014 14:48:43 +0000 (08:48 -0600)
committerTom Tromey <tromey@redhat.com>
Tue, 29 Jul 2014 14:53:15 +0000 (08:53 -0600)
While working on target_is_pushed, I noticed that it is written in a
strange way.  The code currently keeps an extra indirection, where a
simple linked list traversal is all that is needed.  It seems likely
this was done by copying and pasting other code.  However, there is no
reason to do this and the more obvious code is simpler to reason
about.  So, this patch change the implementation.

2014-07-29  Tom Tromey  <tromey@redhat.com>

* target.c (target_is_pushed): Simplify.

gdb/ChangeLog
gdb/target.c

index 10b38cd..460547b 100644 (file)
@@ -1,3 +1,7 @@
+2014-07-29  Tom Tromey  <tromey@redhat.com>
+
+       * target.c (target_is_pushed): Simplify.
+
 2014-07-29  Joel Brobecker  <brobecker@adacore.com>
 
        GDB 7.8 released.
index d9b471b..46186bb 100644 (file)
@@ -671,7 +671,7 @@ pop_all_targets (void)
 int
 target_is_pushed (struct target_ops *t)
 {
-  struct target_ops **cur;
+  struct target_ops *cur;
 
   /* Check magic number.  If wrong, it probably means someone changed
      the struct definition, but not all the places that initialize one.  */
@@ -684,8 +684,8 @@ target_is_pushed (struct target_ops *t)
                      _("failed internal consistency check"));
     }
 
-  for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
-    if (*cur == t)
+  for (cur = target_stack; cur != NULL; cur = cur->beneath)
+    if (cur == t)
       return 1;
 
   return 0;