应用程序无法启动(由于_stprintf_s而导致错误)

时间:2021-08-01 20:54:22

When I execute code in Visual studio 2015, I get the following message
Triggered a breakpoint.
It seems that the error occurs in stdio.h at line 1265

当我在Visual Studio 2015中执行代码时,我收到以下消息触发断点。似乎错误发生在第1265行的stdio.h中

{
    int const _Result = __stdio_common_vswprintf_s( // this is line 1265
        _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS,
        _Buffer, _BufferCount, _Format, _Locale, _ArgList);

    return _Result < 0 ? -1 : _Result;
}

Problem in this line, but I cannot understand why?

问题在这一行,但我不明白为什么?

_stprintf_s(info_temp, _T("\r\n%s"), infoBuf);

Here is my code:

这是我的代码:

    TCHAR* envVarStrings[] =
{
    TEXT("OS         = %OS%"),
    TEXT("PATH       = %PATH%"),
    TEXT("HOMEPATH   = %HOMEPATH%"),
    TEXT("TEMP       = %TEMP%")
};
#define  ENV_VAR_STRING_COUNT  (sizeof(envVarStrings)/sizeof(TCHAR*))
#define INFO_BUFFER_SIZE 32767

void main()
{
    DWORD i;
    TCHAR  infoBuf[INFO_BUFFER_SIZE];
    DWORD  bufCharCount = INFO_BUFFER_SIZE;
    ...
    bufCharCount = ExpandEnvironmentStrings(envVarStrings[1], infoBuf,
            INFO_BUFFER_SIZE);
        TCHAR info_temp[MAX_PATH];
        _stprintf_s(info_temp, _T("\r\n%s"), infoBuf);
        SetWindowText(GetDlgItem(hWnd, ID_EDIT), info_temp);
    ...
}

1 个解决方案

#1


0  

You are not calling _stprintf_s correctly. The second argument should be the size of the destination string.

您没有正确调用_stprintf_s。第二个参数应该是目标字符串的大小。

_stprintf_s(info_temp, MAX_PATH, _T("\r\n%s"), infoBuf);

#1


0  

You are not calling _stprintf_s correctly. The second argument should be the size of the destination string.

您没有正确调用_stprintf_s。第二个参数应该是目标字符串的大小。

_stprintf_s(info_temp, MAX_PATH, _T("\r\n%s"), infoBuf);