From 36f61bf2ad936edfb76eda706eb3b081a61d5a5a Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 2 Sep 2021 09:04:52 +0930 Subject: PTR_ADD and NPTR_ADD for bfd.h This defines a couple of macros used to avoid ubsan complaints about calculations involving NULL pointers. PTR_ADD should be used in the case where it is known that the offset is always zero with a NULL pointer, and you'd like to know if a non-zero offset is ever used. NPTR_ADD should be rarely used, but is defined for cases where a non-zero offset is expected and should be ignored if the pointer is NULL. bfd/ * bfd-in.h (PTR_ADD, NPTR_ADD): Define. * bfd-in2.h: Regenerate. * elf-eh-frame.c (adjust_eh_frame_local_symbols): Avoid NULL pointer calculations. * elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Likewise. (bfd_elf_add_dt_needed_tag, elf_finalize_dynstr): Likewise. (elf_link_add_object_symbols, elf_link_input_bfd): Likewise. (bfd_elf_final_link, bfd_elf_gc_record_vtinherit): Likewise. binutils/ * objdump.c (disassemble_section): Use PTR_ADD for rel_ppend. --- binutils/objdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'binutils') diff --git a/binutils/objdump.c b/binutils/objdump.c index f78b70a..27bfb42 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -3208,7 +3208,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf) } } } - rel_ppend = rel_pp + rel_count; + rel_ppend = PTR_ADD (rel_pp, rel_count); if (!bfd_malloc_and_get_section (abfd, section, &data)) { -- cgit v1.1