Bug 21269 - [4.0/4.1 Regression] member function pointers
Summary: [4.0/4.1 Regression] member function pointers
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P1 critical
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-04-28 19:07 UTC by Yu Yang
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
This is the source file. (375 bytes, text/x-c++src)
2005-04-28 19:08 UTC, Yu Yang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yu Yang 2005-04-28 19:07:32 UTC
I  am trying to print out the value of member function pointers. However, I
found that the compiled executable runs into segment fault. After I added
another local member function pointer variable, the program does not run into
seg fault,but it seems that it gives out incorrect result.
Comment 1 Yu Yang 2005-04-28 19:08:25 UTC
Created attachment 8759 [details]
This is the source file.
Comment 2 Andrew Pinski 2005-04-28 19:16:36 UTC
This works at -O0.
But at -O1 or above.
Comment 3 Andrew Pinski 2005-04-28 19:18:21 UTC
Hmm, this also works just fine on ppc-darwin too.
Comment 4 Andrew Pinski 2005-04-28 19:36:31 UTC
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