我收到一些编译器警告,但我不知道如何修复它们。我自己找不到答案。
int64_t ID = 0;
ID = (int64_t)LOWORD(wParam) - 203;
std::wstring numbersPositive[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" };
std::wstring numbersNegative[] = { L"-0", L"-1", L"-2", L"-3", L"-4", L"-5", L"-6", L"-7", L"-8", L"-9" };
TCHAR Text[MAX_CALCULATOR_OUTPUT_STRING] = { 0 };
GetWindowText(hCalculatorOutput, Text, ARRAYSIZE(Text));
std::wstring WText = Text;
if (WText == L"0") {
SetWindowText(hCalculatorOutput, numbersPositive[ID].c_str());
}
else if (WText[0] == L'-' && WText[1] == L'0' && WText.length() == 2) {
SetWindowText(hCalculatorOutput, numbersNegative[ID].c_str()); // Compiler Warning C6385
}
else {
int64_t length = WText.length();
if (length <= ARRAYSIZE(Text) - 2) {
WText = WText + numbersPositive[ID]; // Compiler Warning C6385
SetWindowText(hCalculatorOutput, WText.c_str());
}
else {
MessageBeep(MB_ICONINFORMATION);
}
}
警告 C6385 从
读取无效数据:可读大小为numbersNegative
字节,但可能会读取400
字节。2613320
警告 C6385 从
读取无效数据:可读大小为numbersPositive
字节,但可能会读取400
字节。2613320
case 203: case 204: case 205: case 206:
case 207: case 208: case 209: case 210:
case 211: case 212:
{
int64_t ID = 0;
ID = (int64_t)LOWORD(wParam) % 10;
(ID >= 3 && ID <= 9) ? ID = ID - 3 : (ID >= 0 && ID <= 2) ? ID = ID + 7 : ID = 0;
std::wstring numbersPositive[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" };
std::wstring numbersNegative[] = { L"-0", L"-1", L"-2", L"-3", L"-4", L"-5", L"-6", L"-7", L"-8", L"-9" };
TCHAR Text[MAX_CALCULATOR_OUTPUT_STRING] = { 0 };
TCHAR ErrorText[40] = { 0 };
GetWindowText(hCalculatorOutput, Text, ARRAYSIZE(Text));
GetWindowText(hCalculatorOutput, ErrorText, ARRAYSIZE(ErrorText));
std::wstring WText = Text;
std::wstring WErrorText = ErrorText;
std::wstring temp1 = numbersPositive[ID];
std::wstring temp2 = numbersNegative[ID];
int64_t length = WText.length();
if (WText == L"0" || WErrorText == L"Infinity" || WErrorText == L"Cannot Divide by Zero") {
WText = temp1;
SetWindowText(hCalculatorOutput, WText.c_str());
}
else if (WText[0] == L'-' && WText[1] == L'0' && length == 2) {
WText = temp2;
SetWindowText(hCalculatorOutput, WText.c_str());
}
else {
if (length < ARRAYSIZE(Text) - 1) {
WText = WText + temp1;
SetWindowText(hCalculatorOutput, WText.c_str());
}
else {
MessageBeep(MB_ICONINFORMATION);
}
}
break;
}
这个答案是由OP user18175085在CC BY-SA 4.0下作为编辑发布到问题编译器警告C6385 - Win32Api - Windows GUI应用程序[已解决]。