]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ctf: fix off-by-one in emitted array bounds
authorNick Alcock <nick.alcock@oracle.com>
Thu, 9 Aug 2012 23:33:14 +0000 (00:33 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Mon, 29 Jun 2015 21:40:29 +0000 (22:40 +0100)
We were treating arrays described by DW_AT_count and DW_AT_upper_bound
identically, but in a language like C with zero-based arrays they are not:
DW_AT_upper_bound does not give the number of members unless you add one
to it.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
scripts/dwarf2ctf/dwarf2ctf.c

index 2464b02496d562601721db06503a4756113cd0ee..87ffd6a275e3063ff2cda42f134210546a4c5679 100644 (file)
@@ -3200,6 +3200,14 @@ static Dwarf_Word private_subrange_dimensions(Dwarf_Die *die)
                return 0;
 
        dwarf_formudata(&nelem_attr, &nelems);
+
+       /*
+        * Upper bounds indicate that we have one more element than that, since
+        * C starts counting at zero.
+        */
+       if (dwarf_hasattr(die, DW_AT_upper_bound))
+               nelems++;
+
        return nelems;
 }