Subject: gcc 2.7.2.2 Bug with NetBSD1.3.2 ??
To: None <netbsd-bugs@netbsd.org>
From: None <crashcore@hell>
List: netbsd-bugs
Date: 10/13/1998 00:13:05
Hello,
I think I've found a bug in gcc 2.7.2.2 that ships with my version of
NetBSD1.3.2. I've tried it under i386 and Amiga with the same result, but now to
the problem. Look at following code:
#include <iostream.h>
#include <string.h>

class Bug {
private:
        char* name;
public:
        Bug(char* n)
        {
            name = new char(strlen(n)+1);
            strcpy(name,n);
        }
        char* get() { return name;}
};
int main()
{
    char* csz = "Hallo";
    Bug a(csz);
    cout << a.get() << endl;
    Bug b(csz);
    cout << a.get() << endl;
    cout << b.get() << endl;
}

And now what happens:
Whenever I create a new bug-object, the name-field of the older object gets
destroyed! In above code this means that the first cout works but the second
(the cout directly after the creation of object b prints not "Hello" but "HellX"
(X stands here for a not printable sign that is shown)
Does someone else have had the same problem:
Please give me an answer (I've tried to get an answer 2 Months ago but didn't
heard anything)
Please write directly to my email-address below! ( I'm not on the list)

thanks,
Jochen Schmidt
crashcore@t-online.de