Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Read Access violation error

Tags:

c++

I am currently getting an "0xC0000005: Access violation reading location 0xcccccce0." error and I have tried diagnose the problem...I think the problem comes in when my rule of 3 that I have defined comes in play and points me to here.

size_type size() const
    {   // return length of sequence
    return (this->_Mysize); <---------------------this line
    }

I'm actually not sure if there is any problem at all, I have been dwelling on this for days on end.

Below is my rule of three

ArrayStorage::ArrayStorage(){
     myArray = new string[7079];
}

ArrayStorage::~ArrayStorage(){
    delete[] _data;
    delete[] myArray;
}

ArrayStorage::ArrayStorage(const ArrayStorage &A) {
    _size = A.size();
    _data = new string [size()];
    for (int i = 0; i < size(); ++i)
        _data[i] = A[i];
}

ArrayStorage& ArrayStorage::operator=(const ArrayStorage &A){
    if (this != &A) {
        delete [] _data;
        _size = A.size();
        _data = new string [A.size()];
        for (int i = 0; i < size(); ++i) {
             _data[i] = A[i];
        }
    }
    return *this;
}

const string& ArrayStorage::operator[](int i) const{
    assert((i >= 0) && (i < size()));
    return _data[i];
}

string& ArrayStorage::operator[](int i){
    assert((i >= 0) && (i < size()));
    return _data[i];
}
like image 615
DorkMonstuh Avatar asked Apr 10 '12 09:04

DorkMonstuh


People also ask

What causes a read access violation?

Anytime your access is denied, you will usually receive an access violation error, which usually reads, “Exception_Access_Violation.” In most cases, it comes with an error code or address. Malware infections and faulty hardware may cause the Exception_Access_Violation issue.

What is access violation error?

An access violation is a non-specific error that occurs while installing, loading, or playing a game. This error can be caused by the following: an interfering software program (usually an antivirus application), an outdated video card driver, or an outdated version of DirectX.

What is an access violation C++?

As its name says, this error occurs whenever you try to access a location that you are not allowed to access in the first place. In other words, whenever you will try to violate the norms of accessing a writing location set up by the C++ programming language, you will always come across this error.

What is exited with code 0xC0000005 access violation?

It is stated that 0xC0000005 error usually occurs when a particular application is trying to access memory, which is no longer available or can't be accessed for some reason.


1 Answers

When uninitialized, stack variables are filled with 0xCC bytes if compiled with msvc. So 0xcccccce0 is probably the result of "this" being an uninitialized pointer variable on the stack plus _MySize offset in the object structure.

like image 68
Nicolas Repiquet Avatar answered Sep 28 '22 05:09

Nicolas Repiquet