Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > correpted stack

Reply
Thread Tools

correpted stack

 
 
Ilia Poliakov
Guest
Posts: n/a
 
      07-22-2003
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


 
Reply With Quote
 
 
 
 
Peter van Merkerk
Guest
Posts: n/a
 
      07-22-2003

"Ilia Poliakov" <(E-Mail Removed)> wrote in message
news:bfj7rm$f0r0a$(E-Mail Removed)-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[i] = 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








 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      07-22-2003
On Tue, 22 Jul 2003 13:40:39 +0200, "Ilia Poliakov" <(E-Mail Removed)> 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.


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      07-22-2003

"Ilia Poliakov" <(E-Mail Removed)> wrote in message
news:bfj7rm$f0r0a$(E-Mail Removed)-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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM
Why stack overflow with such a small stack? Kenneth McDonald Ruby 7 09-01-2007 04:21 AM
"stack level too deep"... because Threads keep their "starting" stack Sam Roberts Ruby 1 02-11-2005 04:25 AM



Advertisments