Commit f330f081 by John Kessenich

Consolidate all token length limits (1024), including one bad one (80) hardcoded…

Consolidate all token length limits (1024), including one bad one (80) hardcoded on the stack (issue #40, issue #41).
parent 1070e629
......@@ -13,7 +13,23 @@ ERROR: 0:35: '' : numeric literal too big
ERROR: 0:36: '' : float literal too long
ERROR: 0:36: '' : float literal too long
ERROR: 0:36: '' : float literal too long
ERROR: 14 compilation errors. No code generated.
WARNING: 0:39: '#extension' : extension not supported: a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhooooooooooooooooooooooooooooooohhhhhhhhhhhhhhhhh01234
ERROR: 0:40: '' : name too long
WARNING: 0:40: '#extension' : extension not supported: a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhooooooooooooooooooooooooooooooohhhhhhhhhhhhhhhhh01234
ERROR: 0:43: '' : name too long
ERROR: 0:44: '#extension' : ':' missing after extension name
ERROR: 0:47: '#error' : in long non - zero # if
ERROR: 0:50: '#error' : in long zero # if
ERROR: 0:52: '' : numeric literal too long
ERROR: 0:53: '#error' : in too long # if
ERROR: 0:56: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile A000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
ERROR: 0:59: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile A000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
ERROR: 0:62: '' : name too long
ERROR: 0:62: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile A000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
ERROR: 0:67: '' : numeric literal too long
ERROR: 0:70: '' : name too long
ERROR: 0:70: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile A000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
ERROR: 28 compilation errors. No code generated.
Shader version: 300
......
......@@ -197,7 +197,7 @@ struct TSourceLoc {
typedef TMap<TString, TString> TPragmaTable;
const int GlslangMaxTokenLength = 1024;
const int MaxTokenLength = 1024;
template <class T> bool IsPow2(T powerOf2)
{
......
......@@ -347,7 +347,7 @@ void TParseContext::outputMessage(TSourceLoc loc, const char* szReason,
const char* szExtraInfoFormat,
TPrefixType prefix, va_list args)
{
const int maxSize = GlslangMaxTokenLength + 200;
const int maxSize = MaxTokenLength + 200;
char szExtraInfo[maxSize];
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
......
......@@ -192,8 +192,8 @@ void TAllocation::checkGuardBlock(unsigned char*, unsigned char, const char*) co
#ifdef GUARD_BLOCKS
for (int x = 0; x < guardBlockSize; x++) {
if (blockMem[x] != val) {
const int maxSize = 80;
char assertMsg[80];
const int maxSize = 80;
char assertMsg[maxSize];
// We don't print the assert message. It's here just to be helpful.
snprintf(assertMsg, maxSize, "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n",
......
......@@ -748,7 +748,7 @@ int TPpContext::CPPextension(TPpToken* ppToken)
{
int line = ppToken->loc.line;
int token = scanToken(ppToken);
char extensionName[80];
char extensionName[MaxTokenLength + 1];
if (token=='\n') {
parseContext.ppError(ppToken->loc, "extension name not specified", "#extension", "");
......@@ -758,6 +758,7 @@ int TPpContext::CPPextension(TPpToken* ppToken)
if (token != PpAtomIdentifier)
parseContext.ppError(ppToken->loc, "extension name expected", "#extension", "");
assert(strlen(ppToken->name) <= MaxTokenLength);
strcpy(extensionName, ppToken->name);
token = scanToken(ppToken);
......
......@@ -102,15 +102,13 @@ public:
}
bool operator!=(const TPpToken& right) { return ! operator==(right); }
static const int maxTokenLength = 1024;
TSourceLoc loc;
int token;
bool space; // true if a space (for white space or a removed comment) should also be recognized, in front of the token returned
int ival;
double dval;
int atom;
char name[maxTokenLength+1];
char name[MaxTokenLength + 1];
};
class TInputScanner;
......
......@@ -129,7 +129,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
str[len++] = (char)ch;
ch = getChar();
while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) {
if (len < MaxTokenLength) {
declen++;
if (len > 0 || ch != '0') {
str[len] = (char)ch;
......@@ -149,7 +149,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
if (ch == 'e' || ch == 'E') {
HasDecimalOrExponent = true;
if (len >= TPpToken::maxTokenLength) {
if (len >= MaxTokenLength) {
parseContext.ppError(ppToken->loc, "float literal too long", "", "");
len = 1;
str_len = 1;
......@@ -165,7 +165,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
}
if (ch >= '0' && ch <= '9') {
while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) {
if (len < MaxTokenLength) {
str[len++] = (char)ch;
ch = getChar();
} else {
......@@ -193,7 +193,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
ungetChar();
ungetChar();
} else {
if (len < TPpToken::maxTokenLength) {
if (len < MaxTokenLength) {
str[len++] = (char)ch;
str[len++] = (char)ch2;
isDouble = 1;
......@@ -208,7 +208,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix");
if (! HasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
str[len++] = (char)ch;
else {
parseContext.ppError(ppToken->loc, "float literal too long", "", "");
......@@ -272,7 +272,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
do {
if (len < TPpToken::maxTokenLength) {
if (len < MaxTokenLength) {
tokenText[len++] = (char)ch;
ch = pp->getChar();
} else {
......@@ -336,7 +336,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
pp->parseContext.ppError(ppToken->loc, "bad digit in hexidecimal literal", "", "");
}
if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isUnsigned = true;
} else
......@@ -358,7 +358,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
// see how much octal-like stuff we can read
while (ch >= '0' && ch <= '7') {
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
......@@ -376,7 +376,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
if (ch == '8' || ch == '9') {
nonOctal = true;
do {
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
......@@ -393,7 +393,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
pp->parseContext.ppError(ppToken->loc, "octal literal digit too large", "", "");
if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
isUnsigned = true;
} else
......@@ -416,7 +416,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
// can't be hexidecimal or octal, is either decimal or floating point
do {
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
......@@ -431,7 +431,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
int numericLen = len;
bool uint = false;
if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength)
if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch;
uint = true;
} else
......@@ -627,7 +627,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
case '"':
ch = pp->getChar();
while (ch != '"' && ch != '\n' && ch != EOF) {
if (len < TPpToken::maxTokenLength) {
if (len < MaxTokenLength) {
tokenText[len] = (char)ch;
len++;
ch = pp->getChar();
......
......@@ -196,7 +196,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
len = 0;
ch = lReadByte(pTok);
while (ch != 0) {
if (len < TPpToken::maxTokenLength) {
if (len < MaxTokenLength) {
tokenText[len] = (char)ch;
len++;
ch = lReadByte(pTok);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment