Skip to content

Commit 381ff7b

Browse files
0-v-0WebFreak001
authored andcommitted
Fix #520: Out of bounds error
1 parent 6ed852f commit 381ff7b

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

src/dparse/ast.d

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,6 +4084,25 @@ unittest //#365 : used to segfault
40844084
Module m1 = parseModule(getTokensForParser(src, cf, &ca), "", &ra , &shut);
40854085
}
40864086

4087+
unittest // issue #520
4088+
{
4089+
import dparse.lexer, dparse.parser, dparse.rollback_allocator;
4090+
4091+
string src = q{void foo(int s =};
4092+
final class Test : ASTVisitor
4093+
{
4094+
}
4095+
4096+
static void shut(string, size_t, size_t, string ,bool){}
4097+
4098+
RollbackAllocator ra;
4099+
auto cf = LexerConfig("", StringBehavior.source);
4100+
auto ca = StringCache(16);
4101+
Module m = parseModule(getTokensForParser(src, cf, &ca), "", &ra, &shut);
4102+
auto t = new Test;
4103+
t.visit(m);
4104+
}
4105+
40874106
unittest // issue #398: Support extern(C++, <string expressions...>)
40884107
{
40894108
import dparse.lexer : LexerConfig;

src/dparse/parser.d

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7413,19 +7413,22 @@ class Parser
74137413
auto startIndex = index;
74147414
auto node = allocator.make!TemplateValueParameterDefault;
74157415
mixin(tokenCheck!"=");
7416-
switch (current.type)
7416+
if (index < tokens.length)
74177417
{
7418-
case tok!"__FILE__":
7419-
case tok!"__FILE_FULL_PATH__":
7420-
case tok!"__MODULE__":
7421-
case tok!"__LINE__":
7422-
case tok!"__FUNCTION__":
7423-
case tok!"__PRETTY_FUNCTION__":
7424-
node.token = advance();
7425-
break;
7426-
default:
7427-
mixin(parseNodeQ!(`node.assignExpression`, `AssignExpression`));
7428-
break;
7418+
switch (current.type)
7419+
{
7420+
case tok!"__FILE__":
7421+
case tok!"__FILE_FULL_PATH__":
7422+
case tok!"__MODULE__":
7423+
case tok!"__LINE__":
7424+
case tok!"__FUNCTION__":
7425+
case tok!"__PRETTY_FUNCTION__":
7426+
node.token = advance();
7427+
break;
7428+
default:
7429+
mixin(parseNodeQ!(`node.assignExpression`, `AssignExpression`));
7430+
break;
7431+
}
74297432
}
74307433
node.tokens = tokens[startIndex .. index];
74317434
return node;

0 commit comments

Comments
 (0)