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.
Created attachment 8759 [details] This is the source file.
This works at -O0. But at -O1 or above.
Hmm, this also works just fine on ppc-darwin too.
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