la corruption de segment détecté | C++

- Je obtenir ce "heap corruption detected" message après l'exécution de ce code :

uli& uli::operator =(char* n)
{
    char* buffer = new char[strlen(n)];

    char* p;
    int op;
    int coef;

    strcpy(buffer, n);

    while(*buffer)
    {
        op = strlen(buffer) - 5;
        p = (op >= 0) ? op+buffer : buffer;
        coef = atoi(p);

        if(coef > 65535)
            coef = atoi(++p);

        push(head, coef);
        *p = '
uli& uli::operator =(char* n)
{
char* buffer = new char[strlen(n)];
char* p;
int op;
int coef;
strcpy(buffer, n);
while(*buffer)
{
op = strlen(buffer) - 5;
p = (op >= 0) ? op+buffer : buffer;
coef = atoi(p);
if(coef > 65535)
coef = atoi(++p);
push(head, coef);
*p = '\0';
}
delete buffer;       // <- heap corruption detected
return *this;
}
'
; } delete buffer; // <- heap corruption detected return *this; }

C'est comme ça que j'appelle la méthode:

uli x;
x = "9876123";

Ce n' "corruption de segment détecté"?

Utilisation delete [] buffer.
Avez-vous bien à l'aide d'un objet pour gérer la mémoire. Peut-être un std::string au lieu d'un char*.
je ne suis pas bon

OriginalL'auteur Jonas | 2012-03-04