MrRoy
MrRoy

Reputation: 1183

First chance exception at 0x5919c8ec (msvcr100d.dll): 0xC0000005: Access violation reading location 0xfeeefeee

I'm having this error while comparing two strings (using an overloaded operator).

The error happens here :

void addEtu(node *Node, element *Etu){
    if (Node->Value == NULL)
        Node->Value = Etu;
    else{
        if (Node->left == NULL && *Node > *Etu) //This line specifically
            Node->left->Value = Etu;
        else if (Node->left != NULL && *Node->left < *Node)
            addEtu(Node->left, Etu);
        else if (Node->right == NULL)
            Node->right->Value = Etu;
        else
            addEtu(Node->right, Etu);
    }
}

And redirects to iosfwd; to this function specifically :

static int __CLRCALL_OR_CDECL compare(const _Elem *_First1, const _Elem *_First2,
        size_t _Count)
        {   // compare [_First1, _First1 + _Count) with [_First2, ...)
        return (_CSTD memcmp(_First1, _First2, _Count));
        }

node is a structure containing two more nodes and 'value', a structure containing a some strings. The overload is as follow :

bool operator>(const node& V1, const node& V2){
    if (V1.Value->Code > V2.Value->Code)
        return true;
    return false;
}

The node taken into parameter by the function addEtu is the root (of a binary tree), it's initialized as follow :

void Initialize(node *Root){
    Root->right = NULL;
    Root->left = NULL;
    Root->Value = NULL;
}

The error happens the second time addEtu is called.

I've no idea what's wrong, I Googled for about an hour and found nothing relevant to my specific error, as any help is appreciated.

Upvotes: 0

Views: 3028

Answers (2)

jdigital
jdigital

Reputation: 12276

It looks like you are storing Etu in the tree, but after you exit addEtu, you are deleting Etu. This means the node in the tree is now pointing to a deleted object.

Upvotes: 0

Eran
Eran

Reputation: 22020

0xFEEEFEEE is a pattern used by VS to mark freed pointers on debug builds. So you have a dangling pointer (namely a pointer you've already freed), which you're trying to dereference. Given Node->left doesn't throw, it's probably Etu.

Upvotes: 3

Related Questions