Mail Archives: cygwin-apps/2001/08/02/02:50:00
DJ Delorie wrote:
>> ret = snprintf (fixup_name, buffer_len, "__fu%d_%s", counter++,
>> sym->name);
>>
>
> Sorry, can't use snprintf.
Why not?
> Use strlen every time (figure 20 for the counter) and compare to the
> max length. Round up to a multiple of 100 to reduce heap
> fragmentation. Then use regular sprintf.
Like this? ('course, you have to #include <math.h> for the ceil
function. Perhaps multiples of 128 or 256 would be better...bit
shifting and masking is easy -- but not really portable...)
-----------------------
static int counter;
static char *fixup_name = NULL;
static int buffer_len = 0;
struct symbol_cache_entry *sym = *rel->sym_ptr_ptr;
bfd *abfd = bfd_asymbol_bfd (sym);
struct coff_link_hash_entry *myh = NULL;
if (!fixup_name)
{
fixup_name = (char *) xmalloc (300);
buffer_len = 300;
}
if (strlen (sym->name) + 25 > buffer_len)
/* assume 25 chars for "__fu" + counter + "_". If counter is
bigger than 20 digits long, we've got worse problems than
overflowing this buffer... */
{
free (fixup_name);
/* new buffer size is length of symbol, plus 25, but then
rounded up to the nearest multiple of 100 */
buffer_len = (int) ((ceil (((double) ( strlen (sym->name) +
25 )) / 100.0)) * 100.0);
fixup_name = (char *) xmalloc (buffer_len);
}
sprintf (fixup_name, "__fu%d_%s", counter++, sym->name);
...
-------------------
FWIW, all of my changes so far (including this one) compile at least.
:-) I'll test actual operation <yawn> tomorrow. (The version I
reported at 11:26EDT 1Aug01, and for which I put binaries on my website
at 1:07EDT 2Aug01, has been minimally tested in operation. It's just
these most recent nit-picky changes that haven't been tested beyond "it
builds"...)
--Chuck
- Raw text -