问题描述
我是否在 wcsrtombs_s
中发现了无法返回给调用者的错误? _TruncATE
宏作为 count
参数提供时,应该在目标字符串的大小已知(数组引用)时防止缓冲区溢出,同时用尽可能多的参数填充 mbstr
参数字符,因为它可以容纳包括空终止符。我已将其定位到 VS 2017 中的 64 位版本。请注意,vcruntime.h
将 size_t
定义为 64 位无符号整数而不是 32 位无符号整数(可能是一个线索?)。作为一个实验,我分别明确地替换了 UINT32_MAX
和 UINT64_MAX
,结果没有变化(回想一下,这些都是像 -1 和 _TruncATE
一样的所有位设置,但它们不同每个尺寸)。根据 Microsoft 文档(找到 here )有问题的重载如下:
template <size_t size>
errno_t wcsrtombs_s(
size_t *pReturnValue,char (&mbstr)[size],const wchar_t **wcstr,sizeof count,mbstate_t *mbstate
); // C++ only
我对 wcsrtombs_s
的第二次调用预期返回值 STruncATE
,但不幸的是从未达到过这样的程度:
const wchar_t wcstr[32] = L"abcdefghijklmnopqrstuvwxyz";
char mbstr[16] = { 0 };
size_t ret_val = 0;
mbstate_t mbstate = { 0 };
wchar_t *pws = wcstr;
// this code returns to the caller
errno_t ret_code = wcsrtombs_s(&ret_val,mbstr,&pws,15,&mbstate);
*mbstr = 0;
mbstate = { 0 };
ret_val = 0;
// this code fails to return to the caller!
ret_code = wcsrtombs_s(&ret_val,_TruncATE,&mbstate);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)