From: Tom Tromey Date: Fri, 20 Jan 2023 00:22:04 +0000 (-0700) Subject: Don't allow NULL as an argument to block_global_block X-Git-Tag: binutils-2_41~1716 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8f14fd112036be4300c81492a4659d518d9caf24;p=thirdparty%2Fbinutils-gdb.git 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. --- diff --git a/gdb/block.c b/gdb/block.c index d21729f069d..5751a6b6f84 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 f7767c980c5..fe56e610a5c 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 598e243b24c..3a380f131cd 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) {