[PATCH] Provide string description of definition, visibility and resolution in LTO plug-in.

Martin Liška mliska@suse.cz
Fri Mar 15 08:51:00 GMT 2019


On 3/14/19 11:42 AM, Nick Clifton wrote:
> Hi Martin,
> 
>> Good point, I reworked that.
> 
> Nice but ...
> 
> +/* Return LTO visibility string name that corresponds to INDEX enum value.  */
> +static const char *
> +get_lto_visibility (unsigned int index)
> 
> [...]
> 
> +  char *buf = xmalloc (64);
> +  sprintf (buf, _("unknown LTO visibility value %x"), index);
> +  return buf;
> 
> This is a memory leak.  (Trivial I know, but someone somewhere
> will complain).  Plus it is a theoretical buffer overrun if the
> translated version of the "unknown LTO visibility" string runs
> to more than ~64 bytes.
> 
> To be safe, I would suggest that you use the concat() function
> from libiberty, rather than xmalloc, and you either provide a
> return flag indicating that a free is needed, or else just
> allocate space for all of the returned strings.  If you think
> that this is overkill (and to be honest I do) then just printing
> into a large static buffer would be fine.

Hi.

I like the static buffer for printing. Note that 64 should be fine
as len(str(1 << 64)) is about 20 characters.

Hope it's fine now?
Thanks,
Martin

> 
> Cheers
>   Nick
> 
> PS.  Of course these remarks apply to the other two new functions
> as well.
> 
> 
> 
>  
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Provide-string-description-of-definition-visibility-.patch
Type: text/x-patch
Size: 4000 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20190315/1d269985/attachment.bin>


More information about the Binutils mailing list