Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2004-10-11 03:00:10 +0000
committerJohn Camelon2004-10-11 03:00:10 +0000
commit06b4f414c0394080a502e8ce63b72b4807db6a11 (patch)
tree7c5d5128089bc8b06e4d5aff5652ca227434b08e /core/org.eclipse.cdt.core
parent9d7f94cc12450e864da01bf483729d292d255c56 (diff)
downloadorg.eclipse.cdt-06b4f414c0394080a502e8ce63b72b4807db6a11.tar.gz
org.eclipse.cdt-06b4f414c0394080a502e8ce63b72b4807db6a11.tar.xz
org.eclipse.cdt-06b4f414c0394080a502e8ce63b72b4807db6a11.zip
Patch for Devin Steffler
Fixed 72611 [Parser] Timeout strategy does not affect scanner infinite loops
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java1
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java17
3 files changed, 17 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
index afd87ca37d3..a5b219c06bc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
@@ -36,5 +36,5 @@ public interface IScanner {
public int getCount();
public boolean isOnTopContext();
public CharArrayObjectMap getRealDefinitions();
-
+ public void cancel();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
index e0abeb8de32..8e2a32fd929 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java
@@ -6275,6 +6275,7 @@ public class Parser implements IParserData, IParser
*/
public synchronized void cancel() {
isCancelled = true;
+ scanner.cancel();
}
/* (non-Javadoc)
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 da4fd282424..0318d675168 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
@@ -31,6 +31,7 @@ import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
+import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
@@ -380,8 +381,13 @@ public class Scanner2 implements IScanner, IScannerData {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final char[] EMPTY_STRING_CHAR_ARRAY = new char[0];
+ private boolean isCancelled = false;
-
+ public synchronized void cancel() {
+ isCancelled = true;
+ int index = bufferStackPos < 0 ? 0 : bufferStackPos;
+ bufferPos[index] = bufferLimit[index];
+ }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScanner#nextToken()
@@ -397,6 +403,8 @@ public class Scanner2 implements IScanner, IScannerData {
{
if( e instanceof OffsetLimitReachedException )
throw (OffsetLimitReachedException) e;
+ if( e instanceof ArrayIndexOutOfBoundsException && isCancelled )
+ throw new ParseError( ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
exception = true;
errorHandle();
@@ -413,6 +421,9 @@ public class Scanner2 implements IScanner, IScannerData {
if (finished)
{
+ if (isCancelled == true)
+ throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
+
if( offsetBoundary == -1 )
throw EOF;
throwOLRE();
@@ -491,7 +502,9 @@ public class Scanner2 implements IScanner, IScannerData {
++count;
contextLoop:
while (bufferStackPos >= 0) {
-
+ if (isCancelled == true)
+ throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
+
// Find the first thing we would care about
skipOverWhiteSpace();

Back to the top