libdw: dwarf_frame_register takes an array of at least 3 Dwarf_Ops
authorMark Wielaard <mark@klomp.org>
Mon, 19 Oct 2020 08:17:59 +0000 (10:17 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 26 Oct 2020 21:44:07 +0000 (22:44 +0100)
commit5621fe5443da23112170235dd5cac161e5c75e65
tree84f8a677b49968f253413aca0a5be2cc1b3b13c1
parente14a5561f7ccb7cec598767d6660a21e8049a818
libdw: dwarf_frame_register takes an array of at least 3 Dwarf_Ops

GCC11 will warn about a mismatch in the declaration of dwarf_frame_register:

dwarf_frame_register.c:37:61: error: argument 3 of type ‘Dwarf_Op *’
  declared as a pointer [-Werror=array-parameter=]
   37 | dwarf_frame_register (Dwarf_Frame *fs, int regno, Dwarf_Op *ops_mem,
      |                                                   ~~~~~~~~~~^~~~~~~
libdw.h:1068:43: note: previously declared as an array ‘Dwarf_Op[3]’
 1068 |                                  Dwarf_Op ops_mem[3],
      |                                  ~~~~~~~~~^~~~~~~~~~

When fixing that it will show an actual bug in the addrcfi testcase:

addrcfi.c:98:16: error: ‘dwarf_frame_register’ accessing 96 bytes in a
  region of size 64 [-Werror=stringop-overflow=]
   98 |   int result = dwarf_frame_register (stuff->frame, regno, ops_mem, &ops, &nops);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
addrcfi.c:98:16: note: referencing argument 3 of type ‘Dwarf_Op *’
 1069 | extern int dwarf_frame_register (Dwarf_Frame *frame, int regno,
      |            ^~~~~~~~~~~~~~~~~~~~

Fix the declaration, fix the bug and add an extra comment to the description
in libdw.h.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_frame_register.c
libdw/libdw.h
tests/ChangeLog
tests/addrcfi.c