Wierd error : Run-Time Check Failure #2

Started by
8 comments, last by Zahlman 17 years, 9 months ago
Here is the error message: Run-Time Check Failure #2 - Stack around the variable 'Line' was corrupted. Why would this be happening?
Advertisement
Most likely you wrote beyond the bounds of an array and into the variable 'Line'.
when this option is turned on the compiler adds extra bytes around your data. At the end of the function it checks the stack to see if any of those bytes have been changes.

If they have then that means you've written on them. Or occasionally you linked in a method with a different calling convention:)

Cheers
Chris
CheersChris
Simian Man : what do you mean by writing beyond the bounds of the array?

chollida1 : Is this an important error or can I turn it off? If it is not important, how do i turn it off?

Thanks.
Its a very important error! It means that your writing to data you don't own. If the data is important, you've now lost it. If the data is unimportant, in release mode you'll overwrite soemthing else.

Cheers
Chris
CheersChris
You can turn it off, but you don't want to. It's telling you that something Serious Wrong has occurred (something that will lead to crashes or strange, hard-to-track down bugs).

Examine the code around the "Line" variable (or post it here) or step through the function in a debugger and see what it is doing wrong.
Quote:Original post by cppcdr
Simian Man : what do you mean by writing beyond the bounds of the array?


Results 1 - 10 of about 1,030,000 for writing beyond the bounds of the array. (0.13 seconds)
Quote:Original post by cppcdr
Simian Man : what do you mean by writing beyond the bounds of the array?


Somthing like this...
const int NOT_BIG_ENOUGH = 10;int array[NOT_BIG_ENOUGH];int Line;       // The corrupted variable// This is OKfor( int i=0; i<NOT_BIG_ENOUGH; i++ ){    array = i;}// This is not OKarray[12] = 0;


You have an array of 10 elements, but change the data of the 13th element. This could be anything. In your case it turned out to be "around the variable 'Line'"

I cannot be more specific without seeing your code.

I hope that helps.
I just figured out the problem.

I was writing to the 90th position when my array was declared as:

char Line [80];

So it was going "overboard".

Thank you all so much!
Quote:Original post by cppcdr
I just figured out the problem.
...
char Line [80];


Yeah, that's the problem all right. Use std::string (assuming C++). :)

This topic is closed to new replies.

Advertisement