This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: other/5554: corrupt this pointer after function call
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 31 Jan 2002 14:36:08 -0000
- Subject: Re: other/5554: corrupt this pointer after function call
- Reply-to: Andrew Pinski <pinskia at physics dot uc dot edu>
The following reply was made to PR other/5554; it has been noted by GNATS.
From: Andrew Pinski <pinskia@physics.uc.edu>
To: jeroenk@allieddata.com
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: other/5554: corrupt this pointer after function call
Date: Thu, 31 Jan 2002 09:31:27 -0500
Try a newer version of gcc and/or gdb. It seems to fixed in ones build
yesterday.
Thanks,
Andrew Pinski
On Thursday, January 31, 2002, at 09:08 , jeroenk@allieddata.com wrote:
>
>> Number: 5554
>> Category: other
>> Synopsis: corrupt this pointer after function call
>> Confidential: no
>> Severity: serious
>> Priority: medium
>> Responsible: unassigned
>> State: open
>> Class: sw-bug
>> Submitter-Id: net
>> Arrival-Date: Thu Jan 31 06:16:00 PST 2002
>> Closed-Date:
>> Last-Modified:
>> Originator: jeroenk@allieddata.com
>> Release: 3.1
>> Organization:
>> Environment:
>
>> Description:
> Hello,
>
> My this pointer becomes corrupt after a function call.
>
> I use the following:
> - gcc & g++ version 3.1
> - libstdc++-3.1-0.17
> - glibc-2.2.90-3
>
> In the debugger (gdb) you can see how the this pointer becommes corrupt.
> Before we call the function we use a backtrace (bt) to resolve the this
> pointer: (0x08048502 in Test::test() (this=0xbffff9e0) )
> After executing the function the this pointer has changed:(0x08048502
> in Test::test() (this=0xbffff9e5))
>
> ______________________________________________________________________
> GNU gdb Red Hat Linux (5.1-2)
> Copyright 2001 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and
> you are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for
> details.
> This GDB was configured as "i386-redhat-linux"...
> (gdb) break 31
> Breakpoint 1 at 0x8048511: file test2.cpp, line 31.
> (gdb) run
> Starting program: /home/jeroenk/qt/monitor/test/test2/./test2
>
> Breakpoint 1, Test::SetCurrentMACaddress(unsigned char*)
> (this=0xbffff9e0,
> TheCurrentMACaddress=0xbffff9b0
> "\001\002\003\004\005\006\001@\210\226\001@\005")
> at test2.cpp:31
> 31 memcpy(CurrentMACaddress, TheCurrentMACaddress, sizeof
> (CurrentMACaddress));
> (gdb) bt
> #0 Test::SetCurrentMACaddress(unsigned char*) (this=0xbffff9e0,
> TheCurrentMACaddress=0xbffff9b0
> "\001\002\003\004\005\006\001@\210\226\001@\005")
> at test2.cpp:31
> #1 0x08048502 in Test::test() (this=0xbffff9e0) at test2.cpp:26
> #2 0x08048572 in main (argc=1, argv=0xbffffa54) at test2.cpp:51
> #3 0x4011e108 in __libc_start_main () from /lib/i686/libc.so.6
> (gdb) next
> 32 }
> (gdb) bt
> #0 Test::SetCurrentMACaddress(unsigned char*) (this=0xbffff9e0,
> TheCurrentMACaddress=0xbffff9b0
> "\001\002\003\004\005\006\001@\210\226\001@\005")
> at test2.cpp:32
> #1 0x08048502 in Test::test() (this=0xbffff9e5) at test2.cpp:26
> #2 0x08048572 in main (argc=1, argv=0xbffffa54) at test2.cpp:51
> #3 0x4011e108 in __libc_start_main () from /lib/i686/libc.so.6
> (gdb)
> ____________________________________________________________________________
>
> However if we use the another pc with the following information:
> gcc & g++ version 2.96
> libstdc++-2.96-98
> glibc-2.2.4-19.3
>
> Everyting works fine.
> ____________________________________________________________________________
> GNU gdb Red Hat Linux (5.1-1)
> Copyright 2001 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and
> you are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for
> details.
> This GDB was configured as "i386-redhat-linux"...
> (gdb) break 31
> Breakpoint 1 at 0x804856d: file test2.cpp, line 31.
> (gdb) run
> Starting program: /home/jeroenk/./test2
>
> Breakpoint 1, Test::SetCurrentMACaddress (this=0xbffff9f0,
> TheCurrentMACaddress=0xbffff9c0 "\001\002\003\004\005\006") at
> test2.cpp:31
> 31 memcpy(CurrentMACaddress, TheCurrentMACaddress, sizeof
> (CurrentMACaddress));
> (gdb) bt
> #0 Test::SetCurrentMACaddress (this=0xbffff9f0,
> TheCurrentMACaddress=0xbffff9c0 "\001\002\003\004\005\006") at
> test2.cpp:31
> #1 0x0804855e in Test::test (this=0xbffff9f0) at test2.cpp:26
> #2 0x080485d2 in main (argc=1, argv=0xbffffa74) at test2.cpp:51
> #3 0x400b4627 in __libc_start_main (main=0x80485c0 <main>, argc=1,
> ubp_av=0xbffffa74,
> init=0x80483bc <_init>, fini=0x8048620 <_fini>,
> rtld_fini=0x4000dcc4 <_dl_fini>,
> stack_end=0xbffffa6c) at ../sysdeps/generic/libc-start.c:129
> (gdb) next
> 32 }
> (gdb) bt
> #0 Test::SetCurrentMACaddress (this=0xbffff9f0,
> TheCurrentMACaddress=0xbffff9c0 "\001\002\003\004\005\006") at
> test2.cpp:32
> #1 0x0804855e in Test::test (this=0xbffff9f0) at test2.cpp:26
> #2 0x080485d2 in main (argc=1, argv=0xbffffa74) at test2.cpp:51
> #3 0x400b4627 in __libc_start_main (main=0x80485c0 <main>, argc=1,
> ubp_av=0xbffffa74,
> init=0x80483bc <_init>, fini=0x8048620 <_fini>,
> rtld_fini=0x4000dcc4 <_dl_fini>,
> stack_end=0xbffffa6c) at ../sysdeps/generic/libc-start.c:129
> (gdb)
> ___________________________________________________________________________
>
> See also attached source file.
>
> What could be the problem?
>> How-To-Repeat:
> see description and file attachment
> If file attachment fails, see source code below:
> -----test2.cpp------
> #include <stddef.h>
>
> typedef unsigned char tMAC[6];
>
> class Test{
>
> public:
> void test();
> private:
> void SetCurrentMACaddress(tMAC TheCurrentMACaddress);
> void *memcpy(void *dest, const void *src, size_t n);
> tMAC CurrentMACaddress;
>
> };
>
> void Test::test()
> {
> tMAC MyMac;
> MyMac[0] = 0x01;
> MyMac[1] = 0x02;
> MyMac[2] = 0x03;
> MyMac[3] = 0x04;
> MyMac[4] = 0x05;
> MyMac[5] = 0x06;
>
> SetCurrentMACaddress(MyMac);
> }
>
> void Test::SetCurrentMACaddress(tMAC TheCurrentMACaddress)
> {
> memcpy(CurrentMACaddress, TheCurrentMACaddress, sizeof
> (CurrentMACaddress));
> }
>
> void *Test::memcpy(void *dest, const void *src, size_t n)
> {
> void * tmp = dest;
>
> while(n--)
> {
> *((char *)dest) = *((char *)src);
> ++(char *)dest;
> ++(char *)src;
> }
> return tmp;
> }
>
> int main( int argc, char ** argv )
> {
> Test a;
>
> a.test();
> }
> -----test2.cpp------
>> Fix:
> None
>> Release-Note:
>> Audit-Trail:
>> Unformatted:
>
>