Skip to content

Commit 9b6b9eb

Browse files
committed
Fix two missing EOF peek() checks, closes #1129
Fix two places where peek(i)->something was not first checking that peek(i) was non-null, to avoid ICEs near the end of the source file
1 parent 27590ee commit 9b6b9eb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

source/parse.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6044,7 +6044,7 @@ class parser
60446044
if (
60456045
peek(1) == nullptr
60466046
|| (t.op = validate_op(curr(), *peek(1))) == nullptr
6047-
)
6047+
)
60486048
{
60496049
break;
60506050
}
@@ -7887,6 +7887,7 @@ class parser
78877887
// Allow a trailing comma in the list
78887888
else if (
78897889
curr().type() == lexeme::Comma
7890+
&& peek(1)
78907891
&& peek(1)->type() == closer
78917892
)
78927893
{
@@ -8584,20 +8585,24 @@ class parser
85848585
{
85858586
auto& type = std::get<declaration_node::an_object>(n->type);
85868587
// object initialized by the address of the curr() object
8587-
if (peek(1)->type() == lexeme::Ampersand) {
8588+
if (peek(1)->type() == lexeme::Ampersand)
8589+
{
85888590
type->address_of = &curr();
85898591
}
85908592
// object initialized by (potentially multiple) dereference of the curr() object
8591-
else if (peek(1)->type() == lexeme::Multiply) {
8593+
else if (peek(1)->type() == lexeme::Multiply)
8594+
{
85928595
type->dereference_of = &curr();
8593-
for (int i = 1; peek(i)->type() == lexeme::Multiply; ++i)
8596+
for (int i = 1; peek(i) && peek(i)->type() == lexeme::Multiply; ++i) {
85948597
type->dereference_cnt += 1;
8598+
}
85958599
}
85968600
else if (
85978601
// object initialized by the result of the function call (and it is not unnamed function)
85988602
(peek(1)->type() == lexeme::LeftParen && curr().type() != lexeme::Colon)
85998603
|| curr().type() == lexeme::Identifier // or by the object (variable that the type need to be checked)
8600-
) {
8604+
)
8605+
{
86018606
type->suspicious_initialization = &curr();
86028607
}
86038608
}

0 commit comments

Comments
 (0)