Run-Time check failure #2-stack around the variable 'sznum' was has upted

Source: Internet
Author: User

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 = en

VS 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.