diff --git a/bfd/ChangeLog b/bfd/ChangeLog index a389fdfc8b1..2ad78033015 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2021-05-20 Andrew Burgess + + * section.c (bfd_get_section_by_name): Return NULL if name is + NULL. + (bfd_get_section_by_name_if): Likewise. + * dwarf2.c (read_section): Remove unneeded NULL check. + (find_debug_info): Likewise. + 2021-05-19 Nick Clifton * plugin.c (bfd_plugin_open_input): Inform the user if the limit diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 0a8a5578da8..cf1f1d1f1ff 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -545,8 +545,7 @@ read_section (bfd * abfd, if (msec == NULL) { section_name = sec->compressed_name; - if (section_name != NULL) - msec = bfd_get_section_by_name (abfd, section_name); + msec = bfd_get_section_by_name (abfd, section_name); } if (msec == NULL) { @@ -4226,12 +4225,9 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections, return msec; look = debug_sections[debug_info].compressed_name; - if (look != NULL) - { - msec = bfd_get_section_by_name (abfd, look); - if (msec != NULL) - return msec; - } + msec = bfd_get_section_by_name (abfd, look); + if (msec != NULL) + return msec; for (msec = abfd->sections; msec != NULL; msec = msec->next) if (startswith (msec->name, GNU_LINKONCE_INFO)) diff --git a/bfd/section.c b/bfd/section.c index a35348833d9..6b6aa92b968 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -898,6 +898,9 @@ bfd_get_section_by_name (bfd *abfd, const char *name) { struct section_hash_entry *sh; + if (name == NULL) + return NULL; + sh = section_hash_lookup (&abfd->section_htab, name, false, false); if (sh != NULL) return &sh->section; @@ -1006,6 +1009,9 @@ bfd_get_section_by_name_if (bfd *abfd, const char *name, struct section_hash_entry *sh; unsigned long hash; + if (name == NULL) + return NULL; + sh = section_hash_lookup (&abfd->section_htab, name, false, false); if (sh == NULL) return NULL;