]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix latent bug in dwarf2_find_containing_comp_unit
authorTom Tromey <tom@tromey.com>
Fri, 21 Feb 2020 01:22:09 +0000 (18:22 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 21 Feb 2020 01:22:09 +0000 (18:22 -0700)
commit22b6cd70430d6bdaa3ae6c01414de8fd1f15a556
tree8d65a7bf4b91e78340ba60d39033a649abb7a78e
parent54b2aec10df9ad032184c556ec9cc3f611a91830
Fix latent bug in dwarf2_find_containing_comp_unit

dwarf2_find_containing_comp_unit has this in its binary search:

      if (mid_cu->is_dwz > offset_in_dwz
  || (mid_cu->is_dwz == offset_in_dwz
      && mid_cu->sect_off + mid_cu->length >= sect_off))
high = mid;

The intent here is to determine whether SECT_OFF appears in or before
MID_CU.

I believe this has an off-by-one error, and that the check should use
">" rather than ">=".  If the two side are equal, then SECT_OFF
actually appears at the start of the next CU.

I've had this patch kicking around for ages but I forget how I found
the problem.

gdb/ChangeLog
2020-02-20  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (dwarf2_find_containing_comp_unit): Use ">", not
">=", in binary search.
(dwarf2_find_containing_comp_unit): New overload.
(run_test): New self-test.
(_initialize_dwarf2_read): Register new test.
gdb/ChangeLog
gdb/dwarf2/read.c