<dwarf>: iteration over attributes swallows the last one
Petr Machata
pmachata at redhat.com
Tue Mar 24 14:21:56 UTC 2009
The scenario goes like this.
* end iterator has an offset of 1
* begin iterator has an offset of 0
* operator ++ does essentially the following:
_m_offset = ::dwarf_getattrs (&_m_die._m_die, &getattrs_callback,
(void *) this, _m_offset);
* operator == takes into account "parental" DIE and _m_offset
getattrs_callback is done such that it answers CB_OK when called the
first time (then it also initializes _m_attr.value), and CB_ABORT when
called the second time. This way dwarf_getattrs returns the position of
_next_ attribute in sequence. But that means that when the last
argument is loaded in _m_attr, _m_offset already has a value of 1, and
evaluates as equal to the end iterator.
As a fix for that, I propose to consider also NULL-ness of _m_attr.value
when doing the iterator comparison. On empty sequences, the callback is
never called, thus leaving _m_attr.value NULL. On sequence of one
element, _m_offset will end up being 1, but _m_attr.value will be
non-NULL. Only after the call to ++ will _m_attr.value become NULL, and
dwarf_getattrs, seeing offset of 1, will immediately return 1 again
without calling the callback. Etc.
Patch attached.
PM
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001--dwarf-Don-t-swallow-last-attribute.patch
Url: https://fedorahosted.org/pipermail/elfutils-devel/attachments/20090324/6460c244/attachment.pl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : https://fedorahosted.org/pipermail/elfutils-devel/attachments/20090324/6460c244/attachment.bin
More information about the elfutils-devel
mailing list