Problem with List class

Hi :)

I have a problem, when i run this code:

Elenco.cpp http://codepaste.net/4zsiy3
Elenco.h http://codepaste.net/pgdqho

Persona.cpp + Persona.h http://codepaste.net/w5koc9

In particular ,when i call l.push_back(P) for insert an persona object in my list i receive this error :

/ERROR

Program: ...12\Projects\ConsoleApplication5\Debug\ConsoleApplication5.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\tcscpy_s.inl
Line: 30

Expression: (L"Buffer is too small" && 0)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.


Someone could help me?
Thanks in advance

Here:
Persona::Persona(char* nomea,char* cognomea){
you did it correctly (+1)

while here:
Persona::Persona(const Persona& that){
and here:
Persona& Persona::operator=(const Persona& that){
you forgot the +1 for the terminating 0
I have correct it . Thanks.

But it produce the same error :(

Post the modified source here (and please use code tags: [code]Your code here[/code])

Your problem is certainly this:

1
2
	nome=new char[16];
	cognome=new char[16];


nome and cognome now point to an uninitialized buffer with random content. strlen() cannot determine a valid length (where is the terminating 0?).
Better set both to NULL and check when you access the variables
Thanks for the advice.


i Had found the problem

1
2
3
4
5
6
7
8
9
10
11
12
Persona::Persona(const Persona& that){
	int ln;
	ln=strlen(that.nome);
	this->nome=new char [ln];
    strcpy_s(this->nome,ln,that.nome);

	int lc;
	lc=strlen(that.cognome);
	this->cognome=new char [lc];
    strcpy_s(this->cognome,lc,thatcognome);

}


I had forgot that before name and cognome -.-

Thanks :)
Last edited on
Topic archived. No new replies allowed.