correpted stack

Discussion in 'C++' started by Ilia Poliakov, Jul 22, 2003.

  1. I have a static function in the class like this:

    class A
    {
    static void f1()
    }

    void A::f1()
    {
    .....
    }

    In f1() I declare a number of local variables and once I become the error
    message:

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

    Is there a stack limit for such case? Or what should I do?

    PS. I work under Win2K MSVC7.0
     
    Ilia Poliakov, Jul 22, 2003
    #1
    1. Advertising

  2. "Ilia Poliakov" <> wrote in message
    news:bfj7rm$f0r0a$-berlin.de...
    > I have a static function in the class like this:
    >
    > class A
    > {
    > static void f1()
    > }
    >
    > void A::f1()
    > {
    > .....
    > }
    >
    > In f1() I declare a number of local variables and once I become the

    error
    > message:
    >
    > Run-Time Check Failure #2 - Stack around the variable '$S28' was

    corrupted.
    >
    > Is there a stack limit for such case? Or what should I do?


    Though stacks have their limits, it is not too likely that that is the
    problem in your case. Most likely it is a bug in your code. But it is
    difficult to tell what exactly the problem is, since you did not post
    minimal yet complete code that demonstrates the problem.

    To give you a clue the following code would lead to stack corruption on
    many systems:

    void A::f1()
    {
    int a[10];

    for(int i=0; i < 20; ++i)
    {
    a = 123456;
    }
    }

    What will happen here depends on compiler, compiler settings and
    platform. But typically when i > 9 this loop will start to overwrite the
    return address,and possibly the 'this' pointer and other function
    arguments, local variables of the calling function and who knows what
    else...


    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
     
    Peter van Merkerk, Jul 22, 2003
    #2
    1. Advertising

  3. On Tue, 22 Jul 2003 13:40:39 +0200, "Ilia Poliakov" <> wrote:

    >I have a static function in the class like this:
    >
    >class A
    >{
    > static void f1()
    >}
    >
    >void A::f1()
    >{
    > .....
    >}
    >
    >In f1() I declare a number of local variables and once I become the error
    >message:
    >
    >Run-Time Check Failure #2 - Stack around the variable '$S28' was corrupted.
    >
    >Is there a stack limit for such case?


    The problem is not related to the function being static.


    >Or what should I do?


    Use a debugger and/or trace output to see what's going wrong. Perhaps
    you have infinite recursion.

    Post more code and information about the problem.
     
    Alf P. Steinbach, Jul 22, 2003
    #3
  4. "Ilia Poliakov" <> wrote in message
    news:bfj7rm$f0r0a$-berlin.de...
    > I have a static function in the class like this:
    >
    > class A
    > {
    > static void f1()
    > }
    >
    > void A::f1()
    > {
    > .....
    > }
    >
    > In f1() I declare a number of local variables and once I become the error
    > message:
    >
    > Run-Time Check Failure #2 - Stack around the variable '$S28' was

    corrupted.
    >
    > Is there a stack limit for such case? Or what should I do?
    >
    > PS. I work under Win2K MSVC7.0
    >


    Its a bug in your program, most likely a buffer oveflow. Post the code,
    we'll fix the bug.

    john
     
    John Harrison, Jul 22, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Surinder Singh
    Replies:
    1
    Views:
    1,214
    Richard Bos
    Dec 20, 2007
  2. Casey Hawthorne
    Replies:
    3
    Views:
    1,104
    Flash Gordon
    Nov 1, 2009
  3. Debajit Adhikary
    Replies:
    36
    Views:
    2,319
    Andre Kaufmann
    Feb 10, 2011
  4. Sam Roberts
    Replies:
    1
    Views:
    228
    Yukihiro Matsumoto
    Feb 11, 2005
  5. Kenneth McDonald

    Why stack overflow with such a small stack?

    Kenneth McDonald, Aug 30, 2007, in forum: Ruby
    Replies:
    7
    Views:
    264
    Kenneth McDonald
    Sep 1, 2007
Loading...

Share This Page