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

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


_dwarf_p_error() is defined in pro_error.c as
 void_dwarf_p_error(Dwarf_P_Debug dbg,
Dwarf_Error * error, Dwarf_Word errval)
{
Dwarf_Error errptr;
want to report the upper-level error, not this one. *//* Allow NULL dbg on 
entry, since sometimes that can happen and weprintf("ERROR VALUE: %ld - %s\n",
(
errptr = (Dwarf_Error)
_dwarf_p_get_alloc(dbg, 
fprintf(stderr,
"Could not allocate Dwarf_Error structure\n");
abort();
}
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 
(
 
 I also could not find any usage in libdwarf of this function where a negative 
value was passed in through errval.
 
Thanks,
Ronunsigned)( -( (signed)errval ) );if((Dwarf_Sword) errval < 0)long) errval, 
_dwarf_errmsgs[-errval - 1]);if(error != NULL) 
{sizeof(structDwarf_Error_s));if(errptr == NULL) {return;


      



More information about the Dwarf-Discuss mailing list