From: Alan Modra Date: Wed, 26 Aug 2020 10:55:04 +0000 (+0930) Subject: PR26507 UBSAN: elf32-xtensa.c:6013 null pointer bsearch X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4d43072582c3ccbb86485d79107a9d3550a1557a;p=binutils-gdb.git PR26507 UBSAN: elf32-xtensa.c:6013 null pointer bsearch PR 26507 * elf32-xtensa.c (find_removed_literal): Don't bsearch empty map. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 765188d303c..988e2f0c649 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2020-08-26 Alan Modra + + PR 26507 + * elf32-xtensa.c (find_removed_literal): Don't bsearch empty map. + 2020-08-26 Alan Modra PR 26506 diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 5184fbf1be7..5824c599ca8 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -6014,13 +6014,16 @@ find_removed_literal (removed_literal_list *removed_list, bfd_vma addr) if (removed_list->map == NULL) map_removed_literal (removed_list); - p = bsearch (&addr, removed_list->map, removed_list->n_map, - sizeof (*removed_list->map), removed_literal_compare); - if (p) + if (removed_list->map != NULL) { - while (p != removed_list->map && (p - 1)->addr == addr) - --p; - r = p->literal; + p = bsearch (&addr, removed_list->map, removed_list->n_map, + sizeof (*removed_list->map), removed_literal_compare); + if (p) + { + while (p != removed_list->map && (p - 1)->addr == addr) + --p; + r = p->literal; + } } return r; }