public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10882: passing and return by reference of char pointer corrupted on x86_64
@ 2003-05-20 13:07 aj
0 siblings, 0 replies; 2+ messages in thread
From: aj @ 2003-05-20 13:07 UTC (permalink / raw)
To: dirkjan, gcc-bugs, gcc-prs, nobody
Synopsis: passing and return by reference of char pointer corrupted on x86_64
State-Changed-From-To: open->closed
State-Changed-By: aj
State-Changed-When: Tue May 20 13:07:52 2003
State-Changed-Why:
The code is invalid, you do the following basically:
int number;
void *ptr;
ptr = &number;
*ptr = NULL;
Note that int is 32-bit and a pointer is 64-bit on x86-64.
You therefore override some random memory, in this case
the string popped_name.
Since your code is not 64-bit clean, and you explicitly
shut GCC up with casts to void, there's not much that GCC can do and it will produce this code.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10882
^ permalink raw reply [flat|nested] 2+ messages in thread
* c++/10882: passing and return by reference of char pointer corrupted on x86_64
@ 2003-05-20 12:36 dirkjan
0 siblings, 0 replies; 2+ messages in thread
From: dirkjan @ 2003-05-20 12:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 10882
>Category: c++
>Synopsis: passing and return by reference of char pointer corrupted on x86_64
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue May 20 12:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: dirkjan@magma-da.com
>Release: gcc-3.2.2 and gcc-3.3
>Organization:
>Environment:
Reading specs from /home/dirkjan/compiler/opteron/gcc-3.2.2/lib/gcc-lib/x86_64-u
nknown-linux-gnu/3.2.2/specs
Configured with: ./configure --prefix=/home/dirkjan/compiler/opteron/gcc-3.2.2 -
-disable-multilib --enable-languages=c,c++
Thread model: posix
gcc version 3.2.2
>Description:
compilation of the following source results in overwriting the char pointer of name. using the second_function there is no problem as well after interchanging the order of the two statements in get_string
include <iostream>
using namespace std;
char* name;
char* ret_string="returned string";
void* first_function(void **data)
{
*data=ret_string;
}
void* second_function(int *data)
{
data=0;
}
void* third_function(void **data)
{
*data=0;
}
void get_string(){
char* popped_name;
int number;
first_function((void**)&popped_name);
//second_function(&number);
third_function((void**)&number);
name=popped_name;
}
main()
{
cout<<"start test"<<endl;
name="initial_name";
cout<<"name is "<<name<<endl;
get_string();
cout<<"name is after functions "<<name<<endl;
}
>How-To-Repeat:
this does only fail on the opteron/x86_64
compilation and run will show the last cout not printing name
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-05-20 13:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-20 13:07 c++/10882: passing and return by reference of char pointer corrupted on x86_64 aj
-- strict thread matches above, loose matches on Subject: below --
2003-05-20 12:36 dirkjan
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).