delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-apps/2001/08/02/02:50:00

Mailing-List: contact cygwin-apps-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-apps-owner AT sourceware DOT cygnus DOT com
List-Subscribe: <mailto:cygwin-apps-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-apps/>
List-Post: <mailto:cygwin-apps AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-apps-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/lists.html#faqs>
Delivered-To: mailing list cygwin-apps AT sources DOT redhat DOT com
Message-ID: <3B68F80C.7030207@ece.gatech.edu>
Date: Thu, 02 Aug 2001 02:49:48 -0400
From: Charles Wilson <cwilson AT ece DOT gatech DOT edu>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010713
X-Accept-Language: en-us
MIME-Version: 1.0
To: DJ Delorie <dj AT delorie DOT com>
CC: binutils AT sources DOT redhat DOT com, cygwin-apps AT cygwin DOT com
Subject: Re: [RFA] pei386 dll: auto-import patch
References: <3B670087 DOT 7090102 AT ece DOT gatech DOT edu> <200108011735 DOT NAA32231 AT envy DOT delorie DOT com> <3B6846D2 DOT 9040206 AT ece DOT gatech DOT edu> <200108011847 DOT OAA32757 AT envy DOT delorie DOT com> <3B68C879 DOT 1070809 AT ece DOT gatech DOT edu> <200108020347 DOT XAA05289 AT envy DOT delorie DOT com> <3B68ED4B DOT 4080405 AT ece DOT gatech DOT edu> <200108020610 DOT CAA06564 AT envy DOT delorie DOT com>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019