public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: jeroenk@allieddata.com
To: gcc-gnats@gcc.gnu.org
Subject: other/5554: corrupt this pointer after function call
Date: Thu, 31 Jan 2002 06:16:00 -0000	[thread overview]
Message-ID: <20020131140851.15619.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-01-31 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-31  6:16 jeroenk [this message]
2002-01-31  6:36 Andrew Pinski
2002-02-07  5:36 Jeroen Kappert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020131140851.15619.qmail@sources.redhat.com \
    --to=jeroenk@allieddata.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).