mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
fix 74176 - [Scanner] ArrayIndexOutOfBoundsException scanning a string
This commit is contained in:
parent
0558ecc1c9
commit
b68b6a74dd
2 changed files with 37 additions and 9 deletions
|
@ -1807,5 +1807,15 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
assertTrue( callback.problems.isEmpty() );
|
assertTrue( callback.problems.isEmpty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug74176() throws Exception{
|
||||||
|
initializeScanner( "#define MYSTRING \"X Y Z " ); //$NON-NLS-1$
|
||||||
|
validateEOF();
|
||||||
|
|
||||||
|
initializeScanner( "#define m(b) #"); //$NON-NLS-1$
|
||||||
|
validateEOF();
|
||||||
|
|
||||||
|
initializeScanner( "#define m(foo,b) #b"); //$NON-NLS-1$
|
||||||
|
validateEOF();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1715,15 +1715,24 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
++bufferPos[bufferStackPos]; //advances us to the #
|
++bufferPos[bufferStackPos]; //advances us to the #
|
||||||
if( skipOverWhiteSpace() )
|
if( skipOverWhiteSpace() )
|
||||||
encounteredMultilineComment = true;
|
encounteredMultilineComment = true;
|
||||||
++bufferPos[bufferStackPos]; //advances us past the # (or last whitespace)
|
|
||||||
boolean isArg = false;
|
boolean isArg = false;
|
||||||
for( int i = 0; i < arglist.length && arglist[i] != null; i++ ){
|
if( bufferPos[bufferStackPos] + 1 < limit )
|
||||||
if( CharArrayUtils.equals( buffer, bufferPos[bufferStackPos], arglist[i].length, arglist[i] ) ){
|
{
|
||||||
isArg = true;
|
++bufferPos[bufferStackPos]; //advances us past the # (or last whitespace)
|
||||||
//advance us to the end of the arg
|
for( int i = 0; i < arglist.length && arglist[i] != null; i++ )
|
||||||
bufferPos[bufferStackPos] += arglist[i].length - 1;
|
{
|
||||||
break;
|
if( bufferPos[bufferStackPos] + arglist[i].length - 1 < limit )
|
||||||
}
|
{
|
||||||
|
if( CharArrayUtils.equals( buffer, bufferPos[bufferStackPos], arglist[i].length, arglist[i] ) )
|
||||||
|
{
|
||||||
|
isArg = true;
|
||||||
|
//advance us to the end of the arg
|
||||||
|
bufferPos[bufferStackPos] += arglist[i].length - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( !isArg )
|
if( !isArg )
|
||||||
handleProblem( IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, bufferPos[bufferStackPos], null );
|
handleProblem( IProblem.PREPROCESSOR_MACRO_PASTING_ERROR, bufferPos[bufferStackPos], null );
|
||||||
|
@ -2055,6 +2064,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
--bufferPos[bufferStackPos];
|
--bufferPos[bufferStackPos];
|
||||||
return encounteredMultiLineComment;
|
return encounteredMultiLineComment;
|
||||||
}
|
}
|
||||||
|
--bufferPos[bufferStackPos];
|
||||||
return encounteredMultiLineComment;
|
return encounteredMultiLineComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2122,6 +2132,11 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
escaped = false;
|
escaped = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//if we hit the limit here, then the outer while loop will advance
|
||||||
|
//us 2 past the end and we'll back up one and still be past the end,
|
||||||
|
//so back up here as well to leave us at the last char.
|
||||||
|
if( bufferPos[bufferStackPos] == bufferLimit[bufferStackPos] )
|
||||||
|
bufferPos[bufferStackPos]--;
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
escaped = false;
|
escaped = false;
|
||||||
|
@ -2141,10 +2156,13 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
escaped = false;
|
escaped = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( bufferPos[bufferStackPos] == bufferLimit[bufferStackPos] )
|
||||||
|
bufferPos[bufferStackPos]--;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case '#' :
|
case '#' :
|
||||||
if( stopAtPound ){
|
if( stopAtPound ){
|
||||||
if( buffer[ bufferPos[bufferStackPos] + 1] != '#' ){
|
if( bufferPos[bufferStackPos] + 1 >= limit || buffer[ bufferPos[bufferStackPos] + 1] != '#' ){
|
||||||
--bufferPos[bufferStackPos];
|
--bufferPos[bufferStackPos];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue