You are here:

C++/stack is corrupted erroe

Advertisement


Question
Hi Zlatko
My program is Matrix transpose and i run it in .net with using MPI.
but i get following run time error:
the stack around variable c is corrupted .
c is  an array.
results from searching net for this error is that maybe data put in stack is more than stack size.
its not true about this program.
do you have any suggestion for me?

Answer
Hello Sara

The message "stack around a variable is corrupted" usually means that you have written to an array using an index which is to large for the array. Arrays are kept on the stack, and going past their bounds will corrupt the stack.

For example, if you declare
int a[10];
and then the program does
a[10] = 1;
That would cause stack corruption because the valid indexes to array a are 0 through 9, and do not include 10. My suggestion is you look at the array accesses and make sure they are all using correct indexes. Perhaps if you have a loop to work on your matrix, make sure the loop counter does not get too large. A common mistake is to have the loop counter go to <= some limit, when it should go to < some limit.

Try disabling parts of your program using comments or using the #if/#endif preprocessor commands and see if that stops the error. Once you get the error to stop, you will have a good idea of which part of the code was causing it.

If you show me the code, then I can help you more. It is OK if it is not C++, I can still read it.

Best regards
Zlatko

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2016 About.com. All rights reserved.