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 ...@@ -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: 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 Shader version: 300
......
...@@ -197,7 +197,7 @@ struct TSourceLoc { ...@@ -197,7 +197,7 @@ struct TSourceLoc {
typedef TMap<TString, TString> TPragmaTable; typedef TMap<TString, TString> TPragmaTable;
const int GlslangMaxTokenLength = 1024; const int MaxTokenLength = 1024;
template <class T> bool IsPow2(T powerOf2) template <class T> bool IsPow2(T powerOf2)
{ {
......
...@@ -347,7 +347,7 @@ void TParseContext::outputMessage(TSourceLoc loc, const char* szReason, ...@@ -347,7 +347,7 @@ void TParseContext::outputMessage(TSourceLoc loc, const char* szReason,
const char* szExtraInfoFormat, const char* szExtraInfoFormat,
TPrefixType prefix, va_list args) TPrefixType prefix, va_list args)
{ {
const int maxSize = GlslangMaxTokenLength + 200; const int maxSize = MaxTokenLength + 200;
char szExtraInfo[maxSize]; char szExtraInfo[maxSize];
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args); safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
......
...@@ -192,8 +192,8 @@ void TAllocation::checkGuardBlock(unsigned char*, unsigned char, const char*) co ...@@ -192,8 +192,8 @@ void TAllocation::checkGuardBlock(unsigned char*, unsigned char, const char*) co
#ifdef GUARD_BLOCKS #ifdef GUARD_BLOCKS
for (int x = 0; x < guardBlockSize; x++) { for (int x = 0; x < guardBlockSize; x++) {
if (blockMem[x] != val) { if (blockMem[x] != val) {
const int maxSize = 80; const int maxSize = 80;
char assertMsg[80]; char assertMsg[maxSize];
// We don't print the assert message. It's here just to be helpful. // 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", snprintf(assertMsg, maxSize, "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n",
......
...@@ -748,7 +748,7 @@ int TPpContext::CPPextension(TPpToken* ppToken) ...@@ -748,7 +748,7 @@ int TPpContext::CPPextension(TPpToken* ppToken)
{ {
int line = ppToken->loc.line; int line = ppToken->loc.line;
int token = scanToken(ppToken); int token = scanToken(ppToken);
char extensionName[80]; char extensionName[MaxTokenLength + 1];
if (token=='\n') { if (token=='\n') {
parseContext.ppError(ppToken->loc, "extension name not specified", "#extension", ""); parseContext.ppError(ppToken->loc, "extension name not specified", "#extension", "");
...@@ -758,6 +758,7 @@ int TPpContext::CPPextension(TPpToken* ppToken) ...@@ -758,6 +758,7 @@ int TPpContext::CPPextension(TPpToken* ppToken)
if (token != PpAtomIdentifier) if (token != PpAtomIdentifier)
parseContext.ppError(ppToken->loc, "extension name expected", "#extension", ""); parseContext.ppError(ppToken->loc, "extension name expected", "#extension", "");
assert(strlen(ppToken->name) <= MaxTokenLength);
strcpy(extensionName, ppToken->name); strcpy(extensionName, ppToken->name);
token = scanToken(ppToken); token = scanToken(ppToken);
......
...@@ -102,15 +102,13 @@ public: ...@@ -102,15 +102,13 @@ public:
} }
bool operator!=(const TPpToken& right) { return ! operator==(right); } bool operator!=(const TPpToken& right) { return ! operator==(right); }
static const int maxTokenLength = 1024;
TSourceLoc loc; TSourceLoc loc;
int token; 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 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; int ival;
double dval; double dval;
int atom; int atom;
char name[maxTokenLength+1]; char name[MaxTokenLength + 1];
}; };
class TInputScanner; class TInputScanner;
......
...@@ -129,7 +129,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ...@@ -129,7 +129,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
str[len++] = (char)ch; str[len++] = (char)ch;
ch = getChar(); ch = getChar();
while (ch >= '0' && ch <= '9') { while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) { if (len < MaxTokenLength) {
declen++; declen++;
if (len > 0 || ch != '0') { if (len > 0 || ch != '0') {
str[len] = (char)ch; str[len] = (char)ch;
...@@ -149,7 +149,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ...@@ -149,7 +149,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
if (ch == 'e' || ch == 'E') { if (ch == 'e' || ch == 'E') {
HasDecimalOrExponent = true; HasDecimalOrExponent = true;
if (len >= TPpToken::maxTokenLength) { if (len >= MaxTokenLength) {
parseContext.ppError(ppToken->loc, "float literal too long", "", ""); parseContext.ppError(ppToken->loc, "float literal too long", "", "");
len = 1; len = 1;
str_len = 1; str_len = 1;
...@@ -165,7 +165,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ...@@ -165,7 +165,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
} }
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
while (ch >= '0' && ch <= '9') { while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) { if (len < MaxTokenLength) {
str[len++] = (char)ch; str[len++] = (char)ch;
ch = getChar(); ch = getChar();
} else { } else {
...@@ -193,7 +193,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ...@@ -193,7 +193,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
ungetChar(); ungetChar();
ungetChar(); ungetChar();
} else { } else {
if (len < TPpToken::maxTokenLength) { if (len < MaxTokenLength) {
str[len++] = (char)ch; str[len++] = (char)ch;
str[len++] = (char)ch2; str[len++] = (char)ch2;
isDouble = 1; isDouble = 1;
...@@ -208,7 +208,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ...@@ -208,7 +208,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken)
parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix"); parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix");
if (! HasDecimalOrExponent) if (! HasDecimalOrExponent)
parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
str[len++] = (char)ch; str[len++] = (char)ch;
else { else {
parseContext.ppError(ppToken->loc, "float literal too long", "", ""); parseContext.ppError(ppToken->loc, "float literal too long", "", "");
...@@ -272,7 +272,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -272,7 +272,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
case 'u': case 'v': case 'w': case 'x': case 'y': case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z': case 'z':
do { do {
if (len < TPpToken::maxTokenLength) { if (len < MaxTokenLength) {
tokenText[len++] = (char)ch; tokenText[len++] = (char)ch;
ch = pp->getChar(); ch = pp->getChar();
} else { } else {
...@@ -336,7 +336,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -336,7 +336,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
pp->parseContext.ppError(ppToken->loc, "bad digit in hexidecimal literal", "", ""); pp->parseContext.ppError(ppToken->loc, "bad digit in hexidecimal literal", "", "");
} }
if (ch == 'u' || ch == 'U') { if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
isUnsigned = true; isUnsigned = true;
} else } else
...@@ -358,7 +358,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -358,7 +358,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
// see how much octal-like stuff we can read // see how much octal-like stuff we can read
while (ch >= '0' && ch <= '7') { while (ch >= '0' && ch <= '7') {
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) { else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", ""); pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
...@@ -376,7 +376,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -376,7 +376,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
if (ch == '8' || ch == '9') { if (ch == '8' || ch == '9') {
nonOctal = true; nonOctal = true;
do { do {
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) { else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", ""); pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
...@@ -393,7 +393,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -393,7 +393,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
pp->parseContext.ppError(ppToken->loc, "octal literal digit too large", "", ""); pp->parseContext.ppError(ppToken->loc, "octal literal digit too large", "", "");
if (ch == 'u' || ch == 'U') { if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
isUnsigned = true; isUnsigned = true;
} else } else
...@@ -416,7 +416,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -416,7 +416,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
// can't be hexidecimal or octal, is either decimal or floating point // can't be hexidecimal or octal, is either decimal or floating point
do { do {
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
else if (! AlreadyComplained) { else if (! AlreadyComplained) {
pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", ""); pp->parseContext.ppError(ppToken->loc, "numeric literal too long", "", "");
...@@ -431,7 +431,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -431,7 +431,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
int numericLen = len; int numericLen = len;
bool uint = false; bool uint = false;
if (ch == 'u' || ch == 'U') { if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength) if (len < MaxTokenLength)
ppToken->name[len++] = (char)ch; ppToken->name[len++] = (char)ch;
uint = true; uint = true;
} else } else
...@@ -627,7 +627,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ...@@ -627,7 +627,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
case '"': case '"':
ch = pp->getChar(); ch = pp->getChar();
while (ch != '"' && ch != '\n' && ch != EOF) { while (ch != '"' && ch != '\n' && ch != EOF) {
if (len < TPpToken::maxTokenLength) { if (len < MaxTokenLength) {
tokenText[len] = (char)ch; tokenText[len] = (char)ch;
len++; len++;
ch = pp->getChar(); ch = pp->getChar();
......
...@@ -196,7 +196,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken) ...@@ -196,7 +196,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
len = 0; len = 0;
ch = lReadByte(pTok); ch = lReadByte(pTok);
while (ch != 0) { while (ch != 0) {
if (len < TPpToken::maxTokenLength) { if (len < MaxTokenLength) {
tokenText[len] = (char)ch; tokenText[len] = (char)ch;
len++; len++;
ch = lReadByte(pTok); 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