Skip to content

Commit 7ad8cc5

Browse files
Change types to avoid overflow-related issues in baseline handling
1 parent 6581486 commit 7ad8cc5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bin/ch/Debugger.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ bool Debugger::SetBaseline()
306306
#ifdef _WIN32
307307
LPSTR script = nullptr;
308308
FILE *file = nullptr;
309-
int numChars = 0;
309+
size_t numChars = 0;
310310
HRESULT hr = S_OK;
311311

312312
if (_wfopen_s(&file, HostConfigFlags::flags.dbgbaseline, _u("rb")) != 0)
@@ -316,13 +316,13 @@ bool Debugger::SetBaseline()
316316

317317
if(file != nullptr)
318318
{
319-
int fileSize = _filelength(_fileno(file));
320-
if (fileSize <= MAX_BASELINE_SIZE)
319+
long fileSize = _filelength(_fileno(file));
320+
if (0 <= fileSize && fileSize <= MAX_BASELINE_SIZE)
321321
{
322-
script = new char[fileSize + 1];
322+
script = new char[(size_t)fileSize + 1];
323323

324-
numChars = static_cast<int>(fread(script, sizeof(script[0]), fileSize, file));
325-
if (numChars == fileSize)
324+
numChars = fread(script, sizeof(script[0]), fileSize, file);
325+
if (numChars == (size_t)fileSize)
326326
{
327327
script[numChars] = '\0';
328328

0 commit comments

Comments
 (0)