[3/4] gdb: make use of scoped_restore in unduplicated_should_be_inserted

Message ID 90be6d987ae6043fdb8c25a0706397ab06eaf437.1664962269.git.aburgess@redhat.com
State Committed
Commit aaa141a0a99fb63f6209da75257c58d94404a963
Headers
Series Const args, int->bool, and scoped_restore in breakpoint.c |

Commit Message

Andrew Burgess Oct. 5, 2022, 9:32 a.m. UTC
  I noticed that we could make use of a scoped_restore in the function
unduplicated_should_be_inserted.  I've also converted the function
return type from int to bool.

This change shouldn't make any difference, as I don't think anything
within should_be_inserted could throw an exception, but the change
doesn't hurt, and will help keep us safe if anything ever changes in
the future.
---
 gdb/breakpoint.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 57281a199b0..e3f3ba3efa6 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2301,16 +2301,13 @@  should_be_inserted (struct bp_location *bl)
 /* Same as should_be_inserted but does the check assuming
    that the location is not duplicated.  */
 
-static int
+static bool
 unduplicated_should_be_inserted (struct bp_location *bl)
 {
-  int result;
-  const int save_duplicate = bl->duplicate;
+  scoped_restore restore_bl_duplicate
+    = make_scoped_restore (&bl->duplicate, 0);
 
-  bl->duplicate = 0;
-  result = should_be_inserted (bl);
-  bl->duplicate = save_duplicate;
-  return result;
+  return should_be_inserted (bl);
 }
 
 /* Parses a conditional described by an expression COND into an