[Dwarf-Discuss] _dwarf_p_error(): Does it correctly handle negative error values?

Ron Louzon louzonr at yahoo.com
Fri Jan 21 07:57:25 PST 2011

Sorry, somehow the original question became garbled.  Here is the same post in 
ungarbled form:

_dwarf_p_error() is defined in pro_error.c as
_dwarf_p_error(Dwarf_P_Debug dbg,
               Dwarf_Error * error, Dwarf_Word errval)
    Dwarf_Error errptr;
    /* Allow NULL dbg on entry, since sometimes that can happen and we
       want to report the upper-level error, not this one. */
    if ((Dwarf_Sword) errval < 0)
        printf("ERROR VALUE: %ld - %s\n",
                (long) errval, _dwarf_errmsgs[-errval - 1]);
    if (error != NULL) {
        errptr = (Dwarf_Error)
            _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_Error_s));
        if (errptr == NULL) {
                    "Could not allocate Dwarf_Error structure\n");
        errptr->er_errval = (Dwarf_Sword) errval;
        *error = errptr;
If the supplied "errval" is negative, the conversion code "-errval-1" is used to 

convert "errval" to a positive index. 
Assume that "errval" had a value of -5.  This conversion generates an index of 4 

which is then used to retrieve a string from the _dwarf_errmsgs table.  Was it 
intended to have an index which is off by 1 or should the conversion be using 
the positive equivalent of "errval" as an index into the _dwarf_errmsgs table?  
It appears to me that the conversion of errval to a positive number should 
really be 
(signed)( -( (signed)errval ) )
I also could not find any usage in libdwarf of this function where a negative 
value was passed in through errval.


More information about the Dwarf-Discuss mailing list