c++/10882: passing and return by reference of char pointer corrupted on x86_64
| Newsgroups | gmane.comp.gcc.prs |
|---|---|
| Message-ID | <20030520122728.22589.qmail__18841.0357143313$1053434165@sources.redhat.com> |
>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: [email protected] >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: