Skip to content

Commit c113d5e

Browse files
committed
Fix parser crash on pointer dereference assignment
Fixed a parser crash that occurred when encountering pointer dereference assignment statements like '*ap = 0;'. The issue was that the parser was trying to find a function named '*ap' before properly handling the pointer dereference syntax. The fix adds a has_asterisk flag to detect when the statement begins with an asterisk operator and skips the function call check in this case, allowing the existing pointer dereference handling code to process the statement correctly.
1 parent ad7db31 commit c113d5e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/parser.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,8 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
32323232
else if (lex_accept(T_decrement))
32333233
prefix_op = OP_sub;
32343234
/* must be an identifier or asterisk (for pointer dereference) */
3235-
if (!lex_peek(T_identifier, token) && !lex_peek(T_asterisk, NULL))
3235+
bool has_asterisk = lex_peek(T_asterisk, NULL);
3236+
if (!lex_peek(T_identifier, token) && !has_asterisk)
32363237
error("Unexpected token");
32373238

32383239
/* handle macro parameter substitution for statements */
@@ -3350,14 +3351,16 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
33503351
return bb;
33513352
}
33523353

3353-
/* is a function call? */
3354-
func = find_func(token);
3355-
if (func) {
3356-
lex_expect(T_identifier);
3357-
read_func_call(func, parent, &bb);
3358-
perform_side_effect(parent, bb);
3359-
lex_expect(T_semicolon);
3360-
return bb;
3354+
/* is a function call? Skip function call check when has_asterisk is true */
3355+
if (!has_asterisk) {
3356+
func = find_func(token);
3357+
if (func) {
3358+
lex_expect(T_identifier);
3359+
read_func_call(func, parent, &bb);
3360+
perform_side_effect(parent, bb);
3361+
lex_expect(T_semicolon);
3362+
return bb;
3363+
}
33613364
}
33623365

33633366
/* handle pointer dereference expressions like *ptr = value */

0 commit comments

Comments
 (0)