Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Visual studio 2008 express edition error (http://www.go4expert.com/forums/visual-studio-2008-express-edition-error-t20096/)

Player 15Nov2009 00:08

Visual studio 2008 express edition error
 
Hi all.

Been pulling my hair out on this one. I keep getting the following error when my program hits return(0);.

Run-Time Check Failure #2 - Stack around the variable 'gamechoice' was corrupted.

I have only just started using this editor so it may be something i'm over looking. The only way to stop it from doing it is to use exit(0);.

Can anyone help?

Thanks in advance :)

Gene Poole 15Nov2009 09:07

Re: Visual studio 2008 express edition error
 
In debug mode, the compiler allocates extra memory on each end of the stack and fills it with a specific value (0xCD I believe). After the function returns, the debug routines check that all those values at the ends of the stack are still what it set at the beginning. If not, it triggers the message you are getting.

In short, you are smashing your stack somehow and the compiler is telling you about it. Fix your code to make it go away.

Player 15Nov2009 21:17

Re: Visual studio 2008 express edition error
 
Quote:

Originally Posted by Gene Poole (Post 60234)
In debug mode, the compiler allocates extra memory on each end of the stack and fills it with a specific value (0xCD I believe). After the function returns, the debug routines check that all those values at the ends of the stack are still what it set at the beginning. If not, it triggers the message you are getting.

In short, you are smashing your stack somehow and the compiler is telling you about it. Fix your code to make it go away.

Thanks for the help but i can't see where it's going wrong. I'll have to stick with the exit(0) for now as i need to get this finished fast. So long as it works now i can always have a look at a later date :)

Gene Poole 15Nov2009 21:38

Re: Visual studio 2008 express edition error
 
Just because it works doesn't mean it's right. When you smash your stack, you invoke undefined behavior. The program may seem to work fine, but there is definitely a problem, and depending on the circumstances, the problem may manifest itself in other unforeseen ways.

Since you are receiving this message, the debugger is protecting you from some of the damage by surrounding your stack with its buffer zone, but in a release build, you'll probably get random unexplained crashes.

Why don't you post the code from your function and see if we can come up with the reason? The debugger should give you a hint that it is "around the variable 'gamechoice'". This is a valuable clue. Perhaps the variable before 'gamechoice' is an array and you are assigning a variable to the array that is out-of-bounds. Perhaps the variable after 'gamechoice' is an array and is being indexed with a negative value. Perhaps 'gamechoice' itself is the problem.

Player 16Nov2009 19:39

Re: Visual studio 2008 express edition error
 
Quote:

Originally Posted by Gene Poole (Post 60257)
Just because it works doesn't mean it's right. When you smash your stack, you invoke undefined behavior. The program may seem to work fine, but there is definitely a problem, and depending on the circumstances, the problem may manifest itself in other unforeseen ways.

Since you are receiving this message, the debugger is protecting you from some of the damage by surrounding your stack with its buffer zone, but in a release build, you'll probably get random unexplained crashes.

Why don't you post the code from your function and see if we can come up with the reason? The debugger should give you a hint that it is "around the variable 'gamechoice'". This is a valuable clue. Perhaps the variable before 'gamechoice' is an array and you are assigning a variable to the array that is out-of-bounds. Perhaps the variable after 'gamechoice' is an array and is being indexed with a negative value. Perhaps 'gamechoice' itself is the problem.


I have examined gamechoice in debug before the return(0) statement and all is as should be.
There is nothing wrong with my code as i have re build my project in C++ 6.0 and theres no issues at all. It's something to do with VS2008, not sure what yet but i'm going to find out.
I spent all weekend building this project, so pretty pissed off that this is happening.

My exe's won't work on certain computers when i build with VS2008, but will work on all when build with C++ 6.0

The facts are that my code is fine, so for now that's all i am concerned about. Thanks for your input :)

EDIT: I may put my code up when i get a chance.


All times are GMT +5.5. The time now is 05:50.