The following running error occurs during program debugging today:
"Run-Time check failure #2-stack around the variable 'sznum' was has upted ."
Then,Yin_xiaogang"Blog found the solution to this problem:
Reprinted address:Http://hi.baidu.com/yin_xiaogang/blog/item/9543b61329847d075aaf53e6.html
Stack around the variable was corrupted2008-07-15
Problem |
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 upted. |
|
Cause |
Stack pointer transaction uption 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 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 ); Int main () { Char * mystr = "Hello World "; Rtc_option_test (mystr ); Return 0; } Int rtc_option_test (char * pstr) { Char buff [buff_len]; Strcpy (buff, pstr); // cause run-time check failure #2-stack around // The variable 'bucket' was upted. Return 0; }
|
|
Related information |
IBM Rational testrt support Http://www-1.ibm.com/support/docview.wss? Rs = 945 & context = ssshuf & context = sssty3 & context = sscsnzn & context = ssstwp & Q1 = stack + around + the + variable + was + synchronized upted & uid = swg21211974 & loc = en_us & cs = UTF-8 & lang = enVS 2005 Change Project-> Configuration properties-> C/C ++-> code generation-> basic runtime check The default value will not report the exception. If it is changed to another one, an exception exists. Exception sometimes makes sense. // Step 1 Stringc2 & stringc2: Operator + = (const char X) { // If (x = 0) return * this; Char PTR [1]; // Max is 1 digit PTR [0] = X; PTR [1] = '/0 '; * This + = PTR; // off to step 2 and back Return * This; // Step 4 crash } This will also cause the above exception |
|