mirror of
https://github.com/microsoft/WSL.git
synced 2025-12-11 23:39:22 -06:00
Only check GetLastError() if ReadFile returns false (#13076)
This commit is contained in:
parent
4b6b3884ba
commit
94ecb86067
@ -1107,13 +1107,17 @@ std::vector<BYTE> wsl::windows::common::wslutil::HashFile(HANDLE file, DWORD Alg
|
|||||||
std::vector<char> buffer(bufferSize);
|
std::vector<char> buffer(bufferSize);
|
||||||
|
|
||||||
DWORD readBytes{};
|
DWORD readBytes{};
|
||||||
while (ReadFile(file, buffer.data(), bufferSize, &readBytes, nullptr) && readBytes > 0)
|
while (true)
|
||||||
{
|
{
|
||||||
|
THROW_IF_WIN32_BOOL_FALSE(ReadFile(file, buffer.data(), bufferSize, &readBytes, nullptr));
|
||||||
|
if (readBytes == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
THROW_IF_WIN32_BOOL_FALSE(CryptHashData(hash.get(), reinterpret_cast<const BYTE*>(buffer.data()), readBytes, 0));
|
THROW_IF_WIN32_BOOL_FALSE(CryptHashData(hash.get(), reinterpret_cast<const BYTE*>(buffer.data()), readBytes, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
THROW_IF_WIN32_ERROR(GetLastError());
|
|
||||||
|
|
||||||
std::vector<BYTE> fileHash(32);
|
std::vector<BYTE> fileHash(32);
|
||||||
DWORD hashSize = static_cast<DWORD>(fileHash.size());
|
DWORD hashSize = static_cast<DWORD>(fileHash.size());
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user