[英]buffer overrun happens in SystemTimeToVariantTime
void ConvertDateIntoSystemFormat(std::wstring dateModified,DATE& date)
{
SYSTEMTIME systemTime;
memset(&systemTime, 0, sizeof(systemTime));
sscanf_s(ConvertWstringToCharStar(dateModified), "%d-%d-%dT%d:%d:%d.%dZ",
&systemTime.wYear, &systemTime.wMonth, &systemTime.wDay, &systemTime.wHour, &systemTime.wMinute, &systemTime.wSecond, &systemTime.wMilliseconds);
SystemTimeToVariantTime(&systemTime, &date);
}
Here is my code. 这是我的代码。 It will convert a wstring which contains date and time into DATE
type. 它将包含日期和时间的wstring转换为DATE
类型。 However, when I run this part of code, it always throw exceptions says "buffer overrun" when the debugger is leaving this function scope. 但是,当我运行这部分代码时,当调试器离开此函数作用域时,它总是会抛出异常,指出“缓冲区溢出”。 I alsy tried to chnage it to void ConvertDateIntoSystemFormat(std::wstring dateModified,DATE* date)
and try to allocate memeory for date when pass it to this function or tried use LPSYSTEMTIME
instead of SYSTEMTIME
, or tried DATE ConvertDateIntoSystemFormat(std::wstring dateModified)
with declare DATE date
inside the function but none of them works, the buffer overrun problem still happens. 我一直试图将其更改为void ConvertDateIntoSystemFormat(std::wstring dateModified,DATE* date)
并尝试在将其传递给此函数时为日期分配void ConvertDateIntoSystemFormat(std::wstring dateModified,DATE* date)
或尝试使用LPSYSTEMTIME
而不是SYSTEMTIME
,或尝试使用DATE ConvertDateIntoSystemFormat(std::wstring dateModified)
在函数中声明了DATE date
,但它们都不起作用,仍然发生缓冲区溢出问题。 How to fix this problem? 如何解决这个问题?
All SYSTEMTIME
fields have WORD
type (aka short
) while format %d
expects a pointer to an int
. 所有SYSTEMTIME
字段都具有WORD
类型(也称为short
),而格式%d
需要一个指向int
的指针。 Fix format string by using %hd
. 使用%hd
修复格式字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.