分类: C/C++
2015-01-10 15:44:02
// Boost.Function library
// Copyright Douglas Gregor 2002-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// )
// For more information, see
#include
#include
#include
#include
#include
#include
#include
using namespace std;
static unsigned
func_impl(int arg1, bool arg2, double arg3)
{
using namespace std;
return abs (static_cast
}
// 带隐患返回指针的函数
char *getStr()
{
char sBuf[12] = "asp";
return sBuf;
}
bool getSafeStr(char *sOutStr, int nStrLen)
{
bool bRet = false;
char sBuf[12] = "asp";
if ( nStrLen
}else{
strcpy(sOutStr, sBuf);
bRet = true;
}
return bRet;
}
int test_main(int, char*[])
{
using boost::function;
using namespace boost::lambda;
function
function
function
string ss;
char *pBuf = getStr();
ss = string(pBuf);
cout << "ss = " << ss << endl;
char strBuf[64];
strcpy(strBuf, getStr());
string s = string(strBuf);
cout << "s = " << s << endl;
memset(strBuf, 0x00, 64);
getSafeStr(strBuf, 64);
cout << "strBuf = " << strBuf << endl;
int n = f3();
return 0;
}
以上代码可配合register,Disassembly调试信息。
由于编译的程序在deBug版下正常,在Release下总莫名其妙的退出,经查证,原来有同事写了很多类似getStr()函数,晕!