• Advertisement
Sign in to follow this  

Wierd error : Run-Time Check Failure #2

This topic is 4259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is the error message: Run-Time Check Failure #2 - Stack around the variable 'Line' was corrupted. Why would this be happening?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 OK
for( int i=0; i<NOT_BIG_ENOUGH; i++ )
{
array = i;
}

// This is not OK
array[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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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++). :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement