diff options
author | Tom Tromey <tom@tromey.com> | 2023-01-19 17:22:04 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2023-02-19 12:51:05 -0700 |
commit | 8f14fd112036be4300c81492a4659d518d9caf24 (patch) | |
tree | 9b9b2cb7ebf975dbc476fc0f543fb06aa18e7c1c | |
parent | 780040961370cb7a9849b83553f03bf7d2f0f9df (diff) | |
download | gdb-8f14fd112036be4300c81492a4659d518d9caf24.zip gdb-8f14fd112036be4300c81492a4659d518d9caf24.tar.gz gdb-8f14fd112036be4300c81492a4659d518d9caf24.tar.bz2 |
Don't allow NULL as an argument to block_global_block
block_global_block has special behavior when the block is NULL.
Remove this and patch up the callers instead.
-rw-r--r-- | gdb/block.c | 6 | ||||
-rw-r--r-- | gdb/cp-support.c | 15 | ||||
-rw-r--r-- | gdb/symtab.c | 5 |
3 files changed, 12 insertions, 14 deletions
diff --git a/gdb/block.c b/gdb/block.c index d21729f..5751a6b 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -378,15 +378,11 @@ block_static_block (const struct block *block) return block; } -/* Return the static block associated to BLOCK. Return NULL if block - is NULL. */ +/* Return the static block associated to BLOCK. */ const struct block * block_global_block (const struct block *block) { - if (block == NULL) - return NULL; - while (block->superblock () != NULL) block = block->superblock (); diff --git a/gdb/cp-support.c b/gdb/cp-support.c index f7767c9..fe56e61 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1309,14 +1309,15 @@ add_symbol_overload_list_namespace (const char *func_name, /* Look in the static block. */ block = get_selected_block (0); block = block == nullptr ? nullptr : block_static_block (block); - if (block) - add_symbol_overload_list_block (name, block, overload_list); - - /* Look in the global block. */ - block = block_global_block (block); - if (block) - add_symbol_overload_list_block (name, block, overload_list); + if (block != nullptr) + { + add_symbol_overload_list_block (name, block, overload_list); + /* Look in the global block. */ + block = block_global_block (block); + if (block) + add_symbol_overload_list_block (name, block, overload_list); + } } /* Search the namespace of the given type and namespace of and public diff --git a/gdb/symtab.c b/gdb/symtab.c index 598e243..3a380f1 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2597,7 +2597,8 @@ lookup_global_symbol (const char *name, /* If a block was passed in, we want to search the corresponding global block first. This yields "more expected" behavior, and is needed to support 'FILENAME'::VARIABLE lookups. */ - const struct block *global_block = block_global_block (block); + const struct block *global_block + = block == nullptr ? nullptr : block_global_block (block); symbol *sym = NULL; if (global_block != nullptr) { @@ -5831,7 +5832,7 @@ default_collect_symbol_completion_matches_break_on b = get_selected_block (0); surrounding_static_block = b == nullptr ? nullptr : block_static_block (b); - surrounding_global_block = block_global_block (b); + surrounding_global_block = b == nullptr : nullptr : block_global_block (b); if (surrounding_static_block != NULL) while (b != surrounding_static_block) { |