Add max-size check conditional

This commit is contained in:
Jack Andersen 2016-02-02 11:34:47 -10:00
parent 26af179ee8
commit 4adfa71c2f
2 changed files with 13 additions and 7 deletions

View File

@ -69,8 +69,11 @@ public:
}
uint64_t write(const void* buf, uint64_t length)
{
if (FTell(fp) + length > m_maxWriteSize)
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
if (m_maxWriteSize >= 0)
{
if (FTell(fp) + length > m_maxWriteSize)
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
}
return fwrite(buf, 1, length, fp);
}
uint64_t copyFromDisc(IPartReadStream& discio, uint64_t length)

View File

@ -72,11 +72,14 @@ public:
}
uint64_t write(const void* buf, uint64_t length)
{
LARGE_INTEGER li = {};
LARGE_INTEGER res;
SetFilePointerEx(fp, li, &res, FILE_CURRENT);
if (res.QuadPart + int64_t(length) > m_maxWriteSize)
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
if (m_maxWriteSize >= 0)
{
LARGE_INTEGER li = {};
LARGE_INTEGER res;
SetFilePointerEx(fp, li, &res, FILE_CURRENT);
if (res.QuadPart + int64_t(length) > m_maxWriteSize)
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
}
DWORD ret = 0;
WriteFile(fp, buf, length, &ret, nullptr);