CString.Format调用失败另一例(buffer too small vsprintf.c Line:244)

来源:互联网 发布:python采集图片教程 编辑:程序博客网 时间:2024/06/09 16:52

之前遇到如下一个问题——

程序运行出错:f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c Line:244”
Expression:("Buffer too small", 0).


最初以为是自己程序中sprintf使用不当造成的,就是就Grep出所有的sprintf,一个一个查,还是没有查出问题所在。

过了许久,已经忘了是哪个线索让我查出来是CString.Format时使用自身作为参数而调用失败了。(奇怪的是这个失败并不总会发生。我们程序中“隐藏”的这个问题年初就存在,可一直没有被发现过,而且可以肯定这段代码测试时被多次执行过。更奇怪的是,这个问题是两个团队几乎同时发现的。难道下面说的“不可预测”还与系统时间有关吗?至今无解!)


MSDN中对这个错误使用有过特别的记载——

The call will fail if the string object itself is offered as a parameter to Format. For example, the following code will cause unpredictable results:

CAtlString str = _T("Some Data");str.Format(_T("%s%d"), str, 123);   // Attention: str is also used in the parameter list.   


参考阅读——

1. 《 CString.Format使用一例》 http://blog.csdn.net/mxclxp/article/details/7393237
2. 《vc中CString::Format出现的Buffer too small错误(转)》 http://blog.csdn.net/zhulingfeng8726/article/details/7077341


原创粉丝点击