diff --git a/code/savever.cpp b/code/savever.cpp index 223e101b..6e6adbf1 100644 --- a/code/savever.cpp +++ b/code/savever.cpp @@ -658,20 +658,29 @@ HRESULT SaveVersionInfo::Load_String(IStorage *storage, int id, char *string) return(res); } + WCHAR buf[128]; + ULONG count; + int i = 0; - while (true) { - WCHAR buf[128]; - res = stm->Read(&buf[i], sizeof(buf[i]), NULL); + for (; i < ARRAY_SIZE(buf); i++) { + res = stm->Read(&buf[i], sizeof(buf[i]), &count); if (FAILED(res)) { return(res); } + if (res != S_OK || count != sizeof(buf[i])) { + return(E_FAIL); + } if (buf[i] == '\0') { - WideCharToMultiByte(CP_ACP, 0, buf, -1, string, ARRAY_SIZE(buf) - 1, 0, 0); - return(res); + break; } - i++; } + if (i == ARRAY_SIZE(buf)) { + return(E_FAIL); + } + + WideCharToMultiByte(CP_ACP, 0, buf, -1, string, ARRAY_SIZE(buf) - 1, 0, 0); + return(S_OK); }