------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-28 
19:36 -------
Actually this is invalid, you are going passed the bounds of buf.  %.2x does 
not do what you want it to 
do.

You want to do the following instead:
void conv_ptr(void * ptr, char* buf)
{
  unsigned char * str = (unsigned char*)ptr;
  int i;
  for(i = 0; i < 3 ; i++)
    sprintf(buf+i*2, "%.2x", str[i]);

  buf[8] = 0;
} 

If you turned on mudflap you would find that we have a violation:
*******
mudflap violation 1 (check/write): time=1114716962.109669 ptr=0xbfe79f35 size=9
pc=0xd40568 location=`(sprintf str)'
      /home/peshtigo/pinskia/linux/lib/libmudflap.so.0(__mf_check+0x48) 
[0xd40568]
      /home/peshtigo/pinskia/linux/lib/libmudflap.so.0(__mfwrap_sprintf+0x16c) 
[0xd4957c]
      ./a.out(_Z8conv_ptrPvPc+0xcc) [0x8048950]
Nearby object 1: checked region begins 2B into and ends 2B after
mudflap object 0x9a2f7d0: name=`t.cc:30 (main) char buf [9]'
bounds=[0xbfe79f33,0xbfe79f3b] size=9 area=stack check=0r/5w liveness=5
alloc time=1114716962.109589 pc=0xd410a8
number of nearby objects: 1

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21269

Reply via email to