Date: Mon, 17 Jan 1994 09:23:23 +0200 (MESZ) From: Christoph Kuhmuench Subject: Re: 'new' runtime error (seg fault) To: Matthew Moss Cc: DJGPP Mailing List Hi Mathew, On Sat, 15 Jan 1994, Matthew Moss wrote: > I have the following class declarations (among others) for a set of execution > commands: > > ////////////////////////////////////////////////// > class Command > { > classes _cl; > char* _name; 0------>^^^^^^^^^^^^^^^^^^^^^^ > > protected: > Command(classes cl,char* name) > { > _cl = cl; > strcpy(_name,name); 1-------------->^^^^^^^^^^^^^^^^^^^ > } > public: > virtual int Perform() = 0; > virtual char* isA() { return "Command"; } > }; > > class C_create:public Command > { > public: > C_create(classes cl,char* name) : Command(cl,name) {} > virtual char* isA() { return "C_create"; } > virtual int Perform() {} > }; > /////////////////////////////////////////////////// > > Now, later on I have the following code > > printf("About to create C_create:\n"); > temp = new C_create(cl,arg[1]); 2------>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > printf("Created C_create successfully!\n"); > Your mistake is, that you use strcpy without allocating memory for _name. The function strcpy doesn't allocate or check if there is enough memory. It simply copies. Try to insert: _name= new char[strlen(name)]; in front of the strcpy line (marked with "1") Greetings Chris