lundi 19 août 2019

how to create testing that will check my checksum ( how to make my code corrupted memory )

I wrote some class that on update of some value - i check the preview checksum and in case checksum is ok i give the option to update the value.

I want to write some test that check the case of the checksum not ok - but i want to do it by doing corrupted memory.

i need to set pointer to the val1 of element 1 in the array and set him to some value - then the checksum will fail .. but i can't find a way to set pointer to this place.

any help please ..

class SafeElementManager
{
std::array<Element, 100> _elements;

void setUpdate(std::string key, int val1, int val2, int val3) {...}
}


class Element
{
std::string _key;
int _val1;
int _val2;
int _val3;
int _checkSumVal;

int calcCheckSum(int val1, int val2, int val3) 
{
    return val1 + val2 + val3
}

bool update(int val1, int val2, int val3)
{
    bool retVal = false; 
    int tmp = calcCheckSum(_val1, _val2, _val3);
    if(tmp == _checkSumVal)
    {
        _checkSumVal = tmp;
        _val1 = val1;
        _val2 = val2;
        _val3 = val3;
        retVal = true;
    }

    return retVal;
}
}

Aucun commentaire:

Enregistrer un commentaire