1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 19:25:38 +02:00

Fix for 180172: Endless loop parsing nsNameSpaceManager.cpp

This commit is contained in:
Anton Leherbauer 2007-03-30 13:06:28 +00:00
parent fcfb9ae587
commit 232528b4b4
2 changed files with 20 additions and 4 deletions

View file

@ -2337,9 +2337,11 @@ abstract class BaseScanner implements IScanner {
char[] result = new char[text.length]; char[] result = new char[text.length];
Arrays.fill(result, ' '); Arrays.fill(result, ' ');
int resultCount = 0; int resultCount = 0;
boolean insideString= false;
boolean backslash= false;
// either a single-line or multi-line comment was found // either a single-line or multi-line comment was found
for (int i = 0; i < text.length; ++i) { for (int i = 0; i < text.length; ++i) {
if (text[i] == '/' && (i + 1 < text.length) && (text[i + 1] == '*' || text[i + 1] == '/')) { if (!insideString && (text[i] == '/' && (i + 1 < text.length) && (text[i + 1] == '*' || text[i + 1] == '/'))) {
if (text[i + 1] == '/') { if (text[i + 1] == '/') {
// done // done
break; break;
@ -2350,9 +2352,17 @@ abstract class BaseScanner implements IScanner {
++i; ++i;
} }
++i; ++i;
} else } else {
if (insideString && !backslash && text[i] == '\\') {
backslash= true;
} else {
backslash= false;
}
if (!backslash && text[i] == '"') {
insideString= !insideString;
}
result[resultCount++] = text[i]; result[resultCount++] = text[i];
}
} }
return CharArrayUtils.trim(result); return CharArrayUtils.trim(result);
} }

View file

@ -655,7 +655,13 @@ public class DOMScanner extends BaseScanner {
public final IToken getNext() { return next; } public final IToken getNext() { return next; }
public void setNext(IToken t) { next = t; } public void setNext(IToken t) {
// guard against endless loop
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=180172
assert t != this : "Token recursion"; //$NON-NLS-1$
if (t != this)
next = t;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple) * @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple)