Skip to content

Commit 966de4e

Browse files
committed
Fix empty files returning an invalid checksum
1 parent 4977bd5 commit 966de4e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Shared/sdk/CChecksum.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ class CChecksum
3636
// GenerateChecksumFromFile returns either a CChecksum or an error message.
3737
static std::variant<CChecksum, std::string> GenerateChecksumFromFile(const SString& strFilename)
3838
{
39+
// Reset error number before using it to report an error
40+
errno = 0;
41+
3942
CChecksum result;
4043
result.ulCRC = CRCGenerator::GetCRCFromFile(strFilename);
4144

42-
if (!result.ulCRC)
45+
if (!result.ulCRC && errno)
4346
return SString("CRC could not open file: %s", std::strerror(errno));
4447

4548
bool success = CMD5Hasher().Calculate(strFilename, result.md5);
49+
4650
if (!success)
4751
return SString("MD5 could not open file: %s", std::strerror(errno));
4852

0 commit comments

Comments
 (0)