Visual studio 2008 express edition error

Discussion in 'C' started by Player, Nov 14, 2009.

  1. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    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 :)
     
  2. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    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.
     
  3. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    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 :)
     
  4. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    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.
     
  5. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0

    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.
     
    Last edited: Nov 16, 2009

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice