This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

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


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.

Cheers
  Nick

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



 


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