zoukankan      html  css  js  c++  java
  • 为什么提示此错误?RunTime Check Failure #2 Stack around the variable 'tch1'was corrupted.

    参考: http://topic.csdn.net/u/20081006/16/859ded6d-7ef1-4b72-b9d8-5ce5d2d7da89.html

    CString CMacroCmd::Ascii2String(CString strAscii)

    {

    #ifdef UNICODE

             CString strValue = _T("");

             TCHAR tch1 = 0x0000;

             for (int i=0; i<strAscii.GetLength()/4; i++)

             {

                       CString stemp1 = strAscii.Mid(i*4, 4);

     

                       _stscanf_s(stemp1.GetBuffer(0),_T("%x"),&tch1);!!!

     

                       CString stemp3;

                       stemp3.Format(_T("%c"), tch1);

                       strValue = strValue+stemp3;

             }

             return strValue;

    #else

             ASSERT(FALSE);    //       必À?须?是º?UNICODE

             return strAscii;

    #endif      

    }

    程序运行完 _stscanf_s(stemp1.GetBuffer(0),_T("%x"),&tch1);

    后在离开次函数时弹出错误提示:
    Run-Time Check Failure #2 - Stack around the variable 'tch1'was corrupted.
    请教高人这是怎么回事?

    -----参考解答:

    sscanf 是一个非常不安全的函数,定义 WORD Step 则 sizeof(Step) = 2,
    VS2005 下 _stscanf_s( XX, _T("%d"), &Step ) 会将输出参数当作 int 类型来写入, sizeof(int) 是4个字节。
    这样会导致多写入2个字节,造成数据的意外破坏。

    而VC6没问题应该是VC6将这个优化了或者忽略了。

    解决方法:int tch1 = 0; //TCHAR tch1 = 0x0000;

  • 相关阅读:
    用原生js实现ajax、jsonp
    $.ajax()方法详解
    用原生js实现ajax
    escape()、encodeURI()、encodeURIComponent()区别详解
    stylus项目知识点
    vue之给a标签赋值
    iOS—网络实用技术OC篇&网络爬虫-使用java语言抓取网络数据
    iOS开发——高级语法篇&继承、实现、依赖、关联、聚合、组合的联系与区别
    iOS-性能优化4
    iOS-性能优化3
  • 原文地址:https://www.cnblogs.com/carl2380/p/2086011.html
Copyright © 2011-2022 走看看