症状
当您运行的应用程序调用_sntscanf_s函数时,则调用应返回EOF(-1)值。但是,当您运行 Windows 10 企业 2015 LTSB 应用程序,请插入的 null 字符将被忽略。这会导致接收错误的值为1 ,而不使用EOF (-1)值的numFields字段。
例如,下面的 Visual C++ 应用程序中发生此问题:
#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
int main()
{
TCHAR szBuff[256];
double temp = 0;
wcscpy_s(szBuff, L"77777777");
// this should force the _sntscanf_s to return an EOF (-1) value
szBuff[0] = '\0';
int numFields = _sntscanf_s(szBuff, _countof(szBuff), _T("%lf"), &temp);
if (numFields == EOF)
{
printf("Correct Behavior!!!\r\n");
}
else
{
printf("BUG: _sntscanf_s failed to return EOF!!!\r\n");
}
return 0;
}
原因
在 Ucrtbase.dll 文件中包含在 Windows 10 企业 2015 LTSB common_vsscanf函数中的已知问题会出现此问题。此问题会影响整个scanf系列的功能:
-
_vsscanf_l
-
vsscanf
-
_sscanf_l
-
sscanf
-
_vsscanf_s_l
-
vsscanf_s
-
_sscanfs_l
-
sscanf_s
-
_snscanf_l
-
_snscanf_s
-
_snscanf_s_l
-
_snscanf_s
-
_vswscanf_l
-
vswscanf
-
_swscanf_l
-
swscanf
-
_vswscanf_s_l
-
vswscanf_s
-
_wsscanfs_l
-
swscanf_s
-
_snwscanf_l
-
_snwscanf_s
-
_snwscanf_s_l
-
_snwscanf_s
解决方案
若要解决此问题,请安装维修更新2018,5 月 8--KB4103716 (操作系统生成 10240.17861)。