mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
Check for shaders without closing brace
Shaders without closing brace can eat shaders in other files. Pass depth to SkipBracedSection instead of reparsing text as it messed up parse line numbers.
This commit is contained in:
parent
c0a21d0898
commit
3ec2b02dce
4 changed files with 41 additions and 21 deletions
|
@ -552,16 +552,14 @@ void COM_MatchToken( char **buf_p, char *match ) {
|
||||||
=================
|
=================
|
||||||
SkipBracedSection
|
SkipBracedSection
|
||||||
|
|
||||||
The next token should be an open brace.
|
The next token should be an open brace or set depth to 1 if already parsed it.
|
||||||
Skips until a matching close brace is found.
|
Skips until a matching close brace is found.
|
||||||
Internal brace depths are properly skipped.
|
Internal brace depths are properly skipped.
|
||||||
=================
|
=================
|
||||||
*/
|
*/
|
||||||
void SkipBracedSection (char **program) {
|
qboolean SkipBracedSection (char **program, int depth) {
|
||||||
char *token;
|
char *token;
|
||||||
int depth;
|
|
||||||
|
|
||||||
depth = 0;
|
|
||||||
do {
|
do {
|
||||||
token = COM_ParseExt( program, qtrue );
|
token = COM_ParseExt( program, qtrue );
|
||||||
if( token[1] == 0 ) {
|
if( token[1] == 0 ) {
|
||||||
|
@ -573,6 +571,8 @@ void SkipBracedSection (char **program) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while( depth && *program );
|
} while( depth && *program );
|
||||||
|
|
||||||
|
return ( depth == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -752,7 +752,7 @@ typedef struct pc_token_s
|
||||||
|
|
||||||
void COM_MatchToken( char**buf_p, char *match );
|
void COM_MatchToken( char**buf_p, char *match );
|
||||||
|
|
||||||
void SkipBracedSection (char **program);
|
qboolean SkipBracedSection (char **program, int depth);
|
||||||
void SkipRestOfLine ( char **data );
|
void SkipRestOfLine ( char **data );
|
||||||
|
|
||||||
void Parse1DMatrix (char **buf_p, int x, float *m);
|
void Parse1DMatrix (char **buf_p, int x, float *m);
|
||||||
|
|
|
@ -2382,7 +2382,7 @@ static char *FindShaderInShaderText( const char *shadername ) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// skip the definition
|
// skip the definition
|
||||||
SkipBracedSection( &p );
|
SkipBracedSection( &p, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2916,6 +2916,8 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
int i;
|
int i;
|
||||||
char *oldp, *token, *hashMem, *textEnd;
|
char *oldp, *token, *hashMem, *textEnd;
|
||||||
int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size;
|
int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size;
|
||||||
|
char shaderName[MAX_QPATH];
|
||||||
|
int shaderLine;
|
||||||
|
|
||||||
long sum = 0, summand;
|
long sum = 0, summand;
|
||||||
// scan for shader files
|
// scan for shader files
|
||||||
|
@ -2945,15 +2947,17 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
|
|
||||||
// Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders.
|
// Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders.
|
||||||
p = buffers[i];
|
p = buffers[i];
|
||||||
|
COM_BeginParseSession(filename);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
token = COM_ParseExt(&p, qtrue);
|
token = COM_ParseExt(&p, qtrue);
|
||||||
|
|
||||||
if(!*token)
|
if(!*token)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
oldp = p;
|
Q_strncpyz(shaderName, token, sizeof(shaderName));
|
||||||
|
shaderLine = COM_GetCurrentParseLine();
|
||||||
|
|
||||||
token = COM_ParseExt(&p, qtrue);
|
token = COM_ParseExt(&p, qtrue);
|
||||||
if(token[0] != '{' || token[1] != '\0')
|
if(token[0] != '{' || token[1] != '\0')
|
||||||
{
|
{
|
||||||
|
@ -2963,8 +2967,14 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipBracedSection(&oldp);
|
if(!SkipBracedSection(&p, 1))
|
||||||
p = oldp;
|
{
|
||||||
|
ri.Printf(PRINT_WARNING, "WARNING: Ignoring shader file %s. Shader \"%s\" on line %d missing closing brace.\n",
|
||||||
|
filename, shaderName, shaderLine);
|
||||||
|
ri.FS_FreeFile(buffers[i]);
|
||||||
|
buffers[i] = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3008,7 +3018,7 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
||||||
shaderTextHashTableSizes[hash]++;
|
shaderTextHashTableSizes[hash]++;
|
||||||
size++;
|
size++;
|
||||||
SkipBracedSection(&p);
|
SkipBracedSection(&p, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size += MAX_SHADERTEXT_HASH;
|
size += MAX_SHADERTEXT_HASH;
|
||||||
|
@ -3034,7 +3044,7 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
||||||
shaderTextHashTable[hash][shaderTextHashTableSizes[hash]++] = oldp;
|
shaderTextHashTable[hash][shaderTextHashTableSizes[hash]++] = oldp;
|
||||||
|
|
||||||
SkipBracedSection(&p);
|
SkipBracedSection(&p, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3018,7 +3018,7 @@ static char *FindShaderInShaderText( const char *shadername ) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// skip the definition
|
// skip the definition
|
||||||
SkipBracedSection( &p );
|
SkipBracedSection( &p, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3542,6 +3542,8 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
int i;
|
int i;
|
||||||
char *oldp, *token, *hashMem, *textEnd;
|
char *oldp, *token, *hashMem, *textEnd;
|
||||||
int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size;
|
int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size;
|
||||||
|
char shaderName[MAX_QPATH];
|
||||||
|
int shaderLine;
|
||||||
|
|
||||||
long sum = 0, summand;
|
long sum = 0, summand;
|
||||||
// scan for shader files
|
// scan for shader files
|
||||||
|
@ -3585,15 +3587,17 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
|
|
||||||
// Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders.
|
// Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders.
|
||||||
p = buffers[i];
|
p = buffers[i];
|
||||||
|
COM_BeginParseSession(filename);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
token = COM_ParseExt(&p, qtrue);
|
token = COM_ParseExt(&p, qtrue);
|
||||||
|
|
||||||
if(!*token)
|
if(!*token)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
oldp = p;
|
Q_strncpyz(shaderName, token, sizeof(shaderName));
|
||||||
|
shaderLine = COM_GetCurrentParseLine();
|
||||||
|
|
||||||
token = COM_ParseExt(&p, qtrue);
|
token = COM_ParseExt(&p, qtrue);
|
||||||
if(token[0] != '{' || token[1] != '\0')
|
if(token[0] != '{' || token[1] != '\0')
|
||||||
{
|
{
|
||||||
|
@ -3603,8 +3607,14 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipBracedSection(&oldp);
|
if(!SkipBracedSection(&p, 1))
|
||||||
p = oldp;
|
{
|
||||||
|
ri.Printf(PRINT_WARNING, "WARNING: Ignoring shader file %s. Shader \"%s\" on line %d missing closing brace.\n",
|
||||||
|
filename, shaderName, shaderLine);
|
||||||
|
ri.FS_FreeFile(buffers[i]);
|
||||||
|
buffers[i] = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3648,7 +3658,7 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
||||||
shaderTextHashTableSizes[hash]++;
|
shaderTextHashTableSizes[hash]++;
|
||||||
size++;
|
size++;
|
||||||
SkipBracedSection(&p);
|
SkipBracedSection(&p, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size += MAX_SHADERTEXT_HASH;
|
size += MAX_SHADERTEXT_HASH;
|
||||||
|
@ -3674,7 +3684,7 @@ static void ScanAndLoadShaderFiles( void )
|
||||||
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
hash = generateHashValue(token, MAX_SHADERTEXT_HASH);
|
||||||
shaderTextHashTable[hash][shaderTextHashTableSizes[hash]++] = oldp;
|
shaderTextHashTable[hash][shaderTextHashTableSizes[hash]++] = oldp;
|
||||||
|
|
||||||
SkipBracedSection(&p);
|
SkipBracedSection(&p, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue