CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    381

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

    What my this runtime error mean? Or what could it mean…

    I had a working app. Compiled in VS 6.0 but now when I compile it in VS .NET this error happens.

    Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.
    ...and justice for all

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    153
    This happens for example if you write to an invalid address.
    Mostly this comes from something like this.
    Code:
    char buffer[3];
    buffer[4] = 'c';
    Then when freeing the Variable buffer when leaving the function-scope, it is stated that the stack around that Variable is corrupted, cause you wrote to invalid address.

    Check your Variable 'cz'. I think somewhere you wrote something out of their bounds.

    Hopen this helps,
    Matze

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

  4. #4
    Join Date
    Oct 2002
    Posts
    209

    Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    Quote Originally Posted by matze42
    This happens for example if you write to an invalid address.
    Mostly this comes from something like this.
    Code:
    char buffer[3];
    buffer[4] = 'c';
    Then when freeing the Variable buffer when leaving the function-scope, it is stated that the stack around that Variable is corrupted, cause you wrote to invalid address.

    Check your Variable 'cz'. I think somewhere you wrote something out of their bounds.

    Hopen this helps,
    Matze
    I am in the exact same situation (start to womder if it was worth my while porting to .NET)

    Is there a way to see what is around the variable on the stack?
    The variable it is complaining about is a bool!

  5. #5
    Join Date
    Sep 2005
    Posts
    2

    Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    hi sirs , does anybody get a solution for the code in this post?

  6. #6
    Join Date
    Aug 2007
    Posts
    19

    Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    Hi, you have to increase the array size in your code. Array value will start from 0 , if you define char buffer[3] then only 0,1,2 are accessible you cannot access buffer[4] because you defined only 3 values.

    char buffer[5] ;
    buffer[4] = 'c';

  7. #7
    Join Date
    Feb 2007
    Posts
    11

    Question Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    Did anyone actually read the line:

    > I had a working app. Compiled in VS 6.0 but now when I compile it in VS .NET this error happens.

    And just because someone has an array in code they showed in their reply, doesn't mean the original poster did. What is it about CONVERTING FROM 'VS 6.0' TO 'VS .NET' that causes this error?

    J.

  8. #8
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    VS .NET detects errors which are not detected by previous versions. However, sometimes such errors do not crash the program. For example, code fragment shown by matze42, may be executed corectly, if another variable on the stack is overritten, and program does not use the variable after this.
    Try to comment off different part of the function and execute it, to find code line which causes this message. If you still has problems, post code fragments here.

  9. #9
    Join Date
    Aug 2006
    Posts
    515

    Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    Do clean and than fresh build the project from scratch helps at times.

  10. #10
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    Quote Originally Posted by zspirit View Post
    Do clean and than fresh build the project from scratch helps at times.
    If only it would be that easy to fix stack corruption!
    BTW, this thread is pretty old, and the issue was explained by Alex F (above).
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  11. #11
    Join Date
    Feb 2014
    Posts
    2

    Thumbs up Re: Run-Time Check Failure #2 - Stack around the variable 'cz' was corrupted.

    Quote Originally Posted by rajprabhu2k View Post
    Hi, you have to increase the array size in your code. Array value will start from 0 , if you define char buffer[3] then only 0,1,2 are accessible you cannot access buffer[4] because you defined only 3 values.

    char buffer[5] ;
    buffer[4] = 'c';
    "thanks brother......."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured