This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

<dwarf>: iteration over attributes swallows the last one


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]