1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 303969: ArrayOutOfBoundsException parsing #error without argument.

This commit is contained in:
Markus Schorn 2010-03-03 09:04:05 +00:00
parent ef1c9cc92b
commit 555761c168
3 changed files with 35 additions and 0 deletions

View file

@ -275,4 +275,27 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase {
validateEOF();
validateProblemCount(0);
}
// #error //
// #warning //
// #pragma // not marked as problem
// #define //
// #include //
// #undef //
// #if //
// #endif
// #ifdef //
// #endif
// #ifndef //
// #endif
// #if 0
// #elif //
// #endif
// a
public void testMissingArgument_Bug303969() throws Exception {
initializeScanner();
validateIdentifier("a");
validateEOF();
validateProblemCount(9);
}
}

View file

@ -1110,6 +1110,10 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
case IPreprocessorDirective.ppError:
int condOffset= lexer.nextToken().getOffset();
condEndOffset= lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
// Missing argument
if (condEndOffset < condOffset) {
condOffset= condEndOffset;
}
if (fCurrentContext.getCodeState() == CodeState.eActive) {
int endOffset= lexer.currentToken().getEndOffset();
final char[] warning= lexer.getInputChars(condOffset, condEndOffset);
@ -1123,6 +1127,10 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
case IPreprocessorDirective.ppPragma:
condOffset= lexer.nextToken().getOffset();
condEndOffset= lexer.consumeLine(ORIGIN_PREPROCESSOR_DIRECTIVE);
// Missing argument
if (condEndOffset < condOffset) {
condOffset= condEndOffset;
}
if (fCurrentContext.getCodeState() == CodeState.eActive) {
int endOffset= lexer.currentToken().getEndOffset();
fLocationMap.encounterPoundPragma(startOffset, condOffset, condEndOffset, endOffset);

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/**
* In short this class converts line endings (to '\n') and trigraphs
@ -1139,6 +1140,9 @@ final public class Lexer implements ITokenSequence {
*/
public char[] getInputChars(int offset, int endOffset) {
final int length= endOffset-offset;
if (length <= 0) {
return CharArrayUtils.EMPTY;
}
final char[] result= new char[length];
fInput.arraycopy(offset, result, 0, length);
return result;