本文介绍了在使用cvisual7TDP进行编译时遇到的“Run-Time Check Failure #2-Stack around the variable 'xxx' was corrupted”错误及其解决方法。此问题通常由在堆栈内存中超出分配缓冲区范围的写操作引起。文章提供了具体的示例代码,并说明了如何通过设置/RTC1编译器选项来启用堆栈帧运行时错误检查。
The following error message occurs when building on Test RealTIme environment with the cvisual7 TDP?
Run-Time Check Failure #2 - Stack around the variable 'xxx' was corrupted.
Cause
Stack pointer corruption is caused writing outside the allocated buffer in stack memeory.
Solution
This kind of error is detected by setting /RTC1 compiler option from menu Project -> Settings -> Configuration properties -> Build -> Compiler -> Compiler flags when using TDP cvisual7 in IBM® Rational® Test RealTime environment.. This enables stack frame run-time error checking. For example, the following code may cause the above error messge.
#include <stdio.h> #include <string.h>
#define BUFF_LEN 11 // 12 may fix the Run-Time Check Failure #2 int rtc_option_test(char * pStr);