Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2004-09-10 16:20:30 +0000
committerAndrew Niefer2004-09-10 16:20:30 +0000
commit8c5c7a12e51a9cee0c84d4bb72492b20d819dfc3 (patch)
treeb488e96baab1b86bd3c4a194ff32771b8cca06df
parenta59a690bb97a069344b1594ab6ee5702715a5e67 (diff)
downloadorg.eclipse.cdt-8c5c7a12e51a9cee0c84d4bb72492b20d819dfc3.tar.gz
org.eclipse.cdt-8c5c7a12e51a9cee0c84d4bb72492b20d819dfc3.tar.xz
org.eclipse.cdt-8c5c7a12e51a9cee0c84d4bb72492b20d819dfc3.zip
handle exceptions and prevent infinite loops. 73652
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java11
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java41
3 files changed, 59 insertions, 6 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
index 398524969b2..a4a49d19f62 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
@@ -2084,4 +2084,15 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertFalse(i.hasNext());
}
+ public void testBug73652() throws Exception
+ {
+ StringWriter writer = new StringWriter();
+ writer.write( "#define DoSuperMethodA IDoSuperMethodA\n" ); //$NON-NLS-1$
+ writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$
+ writer.write( "void hang(void)\n" ); //$NON-NLS-1$
+ writer.write( "{\n" ); //$NON-NLS-1$
+ writer.write( "DoSuperMethodA(0,0,0);\n" ); //$NON-NLS-1$
+ writer.write( "}\n" ); //$NON-NLS-1$
+ parse( writer.toString() , false );
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java
index f1bf8a75288..e0fe9d712cf 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java
@@ -1814,4 +1814,17 @@ public class Scanner2Test extends BaseScanner2Test
validateToken( IToken.t_int );
assertEquals( problems.size(), 1 );
}
+
+ public void testBug73652() throws Exception
+ {
+ StringWriter writer = new StringWriter();
+ writer.write( "#define DoSuperMethodA IDoSuperMethodA\n" ); //$NON-NLS-1$
+ writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$
+ writer.write( "void hang(void)\n" ); //$NON-NLS-1$
+ writer.write( "{\n" ); //$NON-NLS-1$
+ writer.write( "DoSuperMethodA(0,0,0);\n" ); //$NON-NLS-1$
+ writer.write( "}\n" ); //$NON-NLS-1$
+ initializeScanner( writer.toString() );
+ fullyTokenize();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
index 2aa757da8c0..77afc9966ff 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
@@ -362,9 +362,18 @@ public class Scanner2 implements IScanner, IScannerData {
* @see org.eclipse.cdt.core.parser.IScanner#nextToken()
*/
public IToken nextToken() throws ScannerException, EndOfFileException {
+ boolean exception = false;
if (nextToken == null && !finished ) {
- nextToken = fetchToken();
- if (nextToken == null)
+ try
+ {
+ nextToken = fetchToken();
+ }
+ catch( Exception e )
+ {
+ exception = true;
+ errorHandle();
+ }
+ if (nextToken == null && !exception)
{
finished = true;
}
@@ -385,10 +394,22 @@ public class Scanner2 implements IScanner, IScannerData {
lastToken.setNext(nextToken);
IToken oldToken = lastToken;
lastToken = nextToken;
- nextToken = fetchToken();
- if (nextToken == null)
- finished = true;
+ try
+ {
+ nextToken = fetchToken();
+ }
+ catch( Exception e )
+ {
+ nextToken = null;
+ exception = true;
+ errorHandle();
+ }
+
+ if (nextToken == null ){
+ if(!exception)
+ finished = true;
+ }
else if (nextToken.getType() == IToken.tPOUNDPOUND) {
// time for a pasting
IToken token2 = fetchToken();
@@ -421,6 +442,13 @@ public class Scanner2 implements IScanner, IScannerData {
/**
*
*/
+ protected void errorHandle() {
+ ++bufferPos[bufferStackPos];
+ }
+
+ /**
+ *
+ */
private void throwOLRE() throws OffsetLimitReachedException {
if( lastToken != null && lastToken.getEndOffset() != offsetBoundary )
throw new OffsetLimitReachedException( (IToken)null );
@@ -2195,7 +2223,8 @@ public class Scanner2 implements IScanner, IScannerData {
int limit = bufferLimit[bufferStackPos];
skipOverWhiteSpace();
- while( buffer[bufferPos[bufferStackPos]] == '\\' &&
+ while( bufferPos[bufferStackPos] < limit &&
+ buffer[bufferPos[bufferStackPos]] == '\\' &&
bufferPos[bufferStackPos] + 1 < buffer.length &&
buffer[bufferPos[bufferStackPos]+1] == '\n' )
{

Back to the top