Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

狀況

當您執行應用程式呼叫_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;
}

原因

這個問題起因於 Windows 10 企業 2015 LTSB 所隨附的 Ucrtbase.dll 檔案中的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 月 8,-KB4103716 (OS 建置 10240.17861)

參考

很棒的 C 執行階段 (CRT) 重構

引入通用的 CRT

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×