Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Warning C6386 (with array, not fstream)

I was developing a Binary Class that uses three-state booleans to create an array with a clear delimiter (I didn’t want to use vector because I’m stuborn and the code I am using will be transported to an Arduino, which I do not know whether or not it has the std library). Here is the enumeration I used:

enum tribool { DELIM = -1, FALSE, TRUE };

I was developing the Copy Constructor (or Move Constructor, I forgot the difference) of the Binary Class and on "triboolList[i] = (const tribool)copyBinary.triboolList[i];" I was getting Warning C6386.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I looked at Microsoft Learn and I still didn’t understand the problem. I also looked at a stack overflow of this same issue; except the other person was having issues with this warning and std::fstream.

Image of the code because I was having issues with text formatting (Sorry in advance)

Edit: I should clarify that I haven’t found any runtime issues with the Copy Constructor yet, it’s just that the warning is concerning me a little bit

Edit 2: Nevermind, I found some issues. Here is a snippet of the error window: Error snippet

Binary::Binary(Binary& copyBinary, bool alias) { //I had to send a snippet because text formatting wasn't working
    if (alias) {
        triboolList = copyBinary.triboolList; //tribool List is defined as "tribool* triboolList;"
    }
    else {
        triboolList = new tribool[triLength(copyBinary.triboolList)];
        for (int i = 0; i < triLength(copyBinary.triboolList); i++) {
            triboolList[i] = (const tribool)copyBinary.triboolList[i];
        }
        triboolList[triLength(copyBinary.triboolList)] = DELIM;
    }
}

>Solution :

Replace the expression triLength(copyBinary.triboolList) by X:

triboolList = new tribool[X];
for (int i = 0; i < X; i++) {
    triboolList[i] = (const tribool)copyBinary.triboolList[i];
}
triboolList[X] = DELIM;

You can now plainly see the error: it is illegal to access an array of size X at index X, since the last valid index is X-1.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading