Skip to content

Commit dd8f668

Browse files
committed
Fix unchecked peek(1) null deref, closes #326
1 parent cb8c1c5 commit dd8f668

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

source/parse.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5208,18 +5208,18 @@ class parser
52085208
if (deduced_type) {
52095209
auto& type = std::get<declaration_node::an_object>(n->type);
52105210
// object initialized by the address of the curr() object
5211-
if (peek(1)->type() == lexeme::Ampersand) {
5211+
if (peek(1) && peek(1)->type() == lexeme::Ampersand) {
52125212
type->address_of = &curr();
52135213
}
52145214
// object initialized by (potentially multiple) dereference of the curr() object
5215-
else if (peek(1)->type() == lexeme::Multiply) {
5215+
else if (peek(1) && peek(1)->type() == lexeme::Multiply) {
52165216
type->dereference_of = &curr();
52175217
for (int i = 1; peek(i)->type() == lexeme::Multiply; ++i)
52185218
type->dereference_cnt += 1;
52195219
}
52205220
else if (
52215221
// object initialized by the result of the function call (and it is not unnamed function)
5222-
(peek(1)->type() == lexeme::LeftParen && curr().type() != lexeme::Colon)
5222+
(peek(1) && peek(1)->type() == lexeme::LeftParen && curr().type() != lexeme::Colon)
52235223
|| curr().type() == lexeme::Identifier // or by the object (variable that the type need to be checked)
52245224
) {
52255225
type->suspicious_initialization = &curr();

0 commit comments

Comments
 (0)