Extended line limit to 32k

This commit is contained in:
drmortalwombat 2024-08-23 18:16:42 +02:00
parent 967b315be5
commit b48b8b836d
2 changed files with 27 additions and 27 deletions

View File

@ -20,7 +20,7 @@ SourcePath::~SourcePath(void)
} }
bool SourceFile::ReadLineLZO(char* line) bool SourceFile::ReadLineLZO(char* line, ptrdiff_t limit)
{ {
if (mPos > 256) if (mPos > 256)
{ {
@ -61,25 +61,25 @@ bool SourceFile::ReadLineLZO(char* line)
{ {
if (pi > 0) if (pi > 0)
{ {
sprintf_s(line, 1024, "0x%02x, ", pi); sprintf_s(line, limit, "0x%02x, ", pi);
for (int i = 0; i < pi; i++) for (int i = 0; i < pi; i++)
{ {
char buffer[16]; char buffer[16];
sprintf_s(buffer, 16, "0x%02x, ", (unsigned char)mBuffer[mPos - pi + i]); sprintf_s(buffer, 16, "0x%02x, ", (unsigned char)mBuffer[mPos - pi + i]);
strcat_s(line, 1024, buffer); strcat_s(line, limit, buffer);
} }
return true; return true;
} }
else else
{ {
sprintf_s(line, 1024, "0x%02x, 0x%02x, ", 128 + bj, bi); sprintf_s(line, limit, "0x%02x, 0x%02x, ", 128 + bj, bi);
mPos += bj; mPos += bj;
if (mFill == mPos) if (mFill == mPos)
strcat_s(line, 1024, "0x00, "); strcat_s(line, limit, "0x00, ");
return true; return true;
} }
@ -91,18 +91,18 @@ bool SourceFile::ReadLineLZO(char* line)
} }
} }
sprintf_s(line, 1024, "0x%02x, ", pi); sprintf_s(line, limit, "0x%02x, ", pi);
for (int i = 0; i < pi; i++) for (int i = 0; i < pi; i++)
{ {
char buffer[16]; char buffer[16];
sprintf_s(buffer, 16, "0x%02x, ", (unsigned char)mBuffer[mPos - pi + i]); sprintf_s(buffer, 16, "0x%02x, ", (unsigned char)mBuffer[mPos - pi + i]);
strcat_s(line, 1024, buffer); strcat_s(line, limit, buffer);
} }
if (mFill == mPos) if (mFill == mPos)
strcat_s(line, 1024, "0x00, "); strcat_s(line, limit, "0x00, ");
return true; return true;
} }
@ -110,7 +110,7 @@ bool SourceFile::ReadLineLZO(char* line)
return false; return false;
} }
bool SourceFile::ReadLineRLE(char* line) bool SourceFile::ReadLineRLE(char* line, ptrdiff_t limit)
{ {
assert(mFill >= 0 && mFill < 256); assert(mFill >= 0 && mFill < 256);
@ -148,7 +148,7 @@ bool SourceFile::ReadLineRLE(char* line)
if (rcnt > 0) if (rcnt > 0)
{ {
sprintf_s(line, 1024, "0x%02x, 0x%02x, ", 0x80 + ((cnt - 1) << 4) + (rcnt - 1), (unsigned char)mBuffer[0]); sprintf_s(line, limit, "0x%02x, 0x%02x, ", 0x80 + ((cnt - 1) << 4) + (rcnt - 1), (unsigned char)mBuffer[0]);
assert(mFill >= 0 && mFill <= 256); assert(mFill >= 0 && mFill <= 256);
@ -159,7 +159,7 @@ bool SourceFile::ReadLineRLE(char* line)
assert(mFill >= 0 && mFill <= 256); assert(mFill >= 0 && mFill <= 256);
strcat_s(line, 1024, buffer); strcat_s(line, limit, buffer);
assert(mFill >= 0 && mFill <= 256); assert(mFill >= 0 && mFill <= 256);
} }
@ -174,7 +174,7 @@ bool SourceFile::ReadLineRLE(char* line)
} }
else else
{ {
sprintf_s(line, 1024, "0x%02x, 0x%02x, ", 0x00 + (cnt - 1), (unsigned char)mBuffer[0]); sprintf_s(line, limit, "0x%02x, 0x%02x, ", 0x00 + (cnt - 1), (unsigned char)mBuffer[0]);
memmove(mBuffer, mBuffer + cnt, mFill - cnt); memmove(mBuffer, mBuffer + cnt, mFill - cnt);
mFill -= cnt; mFill -= cnt;
@ -183,7 +183,7 @@ bool SourceFile::ReadLineRLE(char* line)
} }
else else
{ {
sprintf_s(line, 1024, "0x%02x, 0x%02x, ", 0x00 + (cnt - 1), (unsigned char)mBuffer[0]); sprintf_s(line, limit, "0x%02x, 0x%02x, ", 0x00 + (cnt - 1), (unsigned char)mBuffer[0]);
memmove(mBuffer, mBuffer + cnt, mFill - cnt); memmove(mBuffer, mBuffer + cnt, mFill - cnt);
mFill -= cnt; mFill -= cnt;
@ -191,7 +191,7 @@ bool SourceFile::ReadLineRLE(char* line)
} }
if (mFill == 0) if (mFill == 0)
strcat_s(line, 1024, "0x00, "); strcat_s(line, limit, "0x00, ");
return true; return true;
} }
@ -210,13 +210,13 @@ bool SourceFile::ReadLineRLE(char* line)
if (cnt < mFill && rep >= 3) if (cnt < mFill && rep >= 3)
cnt -= rep; cnt -= rep;
sprintf_s(line, 1024, "0x%02x, ", 0x40 + (cnt - 1)); sprintf_s(line, limit, "0x%02x, ", 0x40 + (cnt - 1));
for (int i = 0; i < cnt; i++) for (int i = 0; i < cnt; i++)
{ {
char buffer[16]; char buffer[16];
sprintf_s(buffer, 16, "0x%02x, ", (unsigned char)mBuffer[i]); sprintf_s(buffer, 16, "0x%02x, ", (unsigned char)mBuffer[i]);
strcat_s(line, 1024, buffer); strcat_s(line, limit, buffer);
} }
memmove(mBuffer, mBuffer + cnt, mFill - cnt); memmove(mBuffer, mBuffer + cnt, mFill - cnt);
@ -225,7 +225,7 @@ bool SourceFile::ReadLineRLE(char* line)
assert(mFill >= 0 && mFill < 256); assert(mFill >= 0 && mFill < 256);
if (mFill == 0) if (mFill == 0)
strcat_s(line, 1024, "0x00, "); strcat_s(line, limit, "0x00, ");
return true; return true;
} }
@ -247,14 +247,14 @@ int SourceFile::ReadChar(void)
return fgetc(mFile); return fgetc(mFile);
} }
bool SourceFile::ReadLine(char* line) bool SourceFile::ReadLine(char* line, ptrdiff_t limit)
{ {
if (mFile) if (mFile)
{ {
switch (mMode) switch (mMode)
{ {
case SFM_TEXT: case SFM_TEXT:
if (fgets(line, 1024, mFile)) if (fgets(line, int(limit), mFile))
return true; return true;
break; break;
case SFM_BINARY: case SFM_BINARY:
@ -265,7 +265,7 @@ bool SourceFile::ReadLine(char* line)
int c = ReadChar(); int c = ReadChar();
if (c >= 0) if (c >= 0)
{ {
sprintf_s(line, 1024, "0x%02x, ", c); sprintf_s(line, limit, "0x%02x, ", c);
return true; return true;
} }
} }
@ -280,18 +280,18 @@ bool SourceFile::ReadLine(char* line)
{ {
int d = ReadChar(); int d = ReadChar();
if (d >= 0) if (d >= 0)
sprintf_s(line, 1024, "0x%04x, ", c + 256 * d); sprintf_s(line, limit, "0x%04x, ", c + 256 * d);
return true; return true;
} }
} }
break; break;
case SFM_BINARY_RLE: case SFM_BINARY_RLE:
if (ReadLineRLE(line)) if (ReadLineRLE(line, limit))
return true; return true;
break; break;
case SFM_BINARY_LZO: case SFM_BINARY_LZO:
if (ReadLineLZO(line)) if (ReadLineLZO(line, limit))
return true; return true;
break; break;
} }
@ -827,7 +827,7 @@ bool SourceFile::DropSource(void)
bool Preprocessor::NextLine(void) bool Preprocessor::NextLine(void)
{ {
ptrdiff_t s = 0; ptrdiff_t s = 0;
while (mSource->ReadLine(mLine + s)) while (s < 32768 && mSource->ReadLine(mLine + s, 32768 - s))
{ {
mLocation.mLine++; mLocation.mLine++;

View File

@ -52,10 +52,10 @@ public:
int mFill, mPos, mMemPos, mMemSize; int mFill, mPos, mMemPos, mMemSize;
uint8 * mMemData; uint8 * mMemData;
bool ReadLine(char* line); bool ReadLine(char* line, ptrdiff_t limit);
bool ReadLineRLE(char* line); bool ReadLineRLE(char* line, ptrdiff_t limit);
bool ReadLineLZO(char* line); bool ReadLineLZO(char* line, ptrdiff_t limit);
SourceFile(void); SourceFile(void);
~SourceFile(void); ~SourceFile(void);