From 7fe9c22cf28aa6fa63d48605335672492282a7a8 Mon Sep 17 00:00:00 2001 From: Benjamin Oldenburg Date: Fri, 20 Mar 2026 19:59:27 +0700 Subject: [PATCH] arm64-asm.c: reject invalid registers in address operands parse_addr_operand() silently accepted invalid register names like [xyz] without error. Now explicitly validates the register and calls tcc_error() if arm64_parse_regvar() returns -1 or >= 32. Before: invalid registers caused silent wrong code or confusing errors After: clear error message 'invalid register in address operand' --- arm64-asm.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/arm64-asm.c b/arm64-asm.c index 9ad446e6..1897cacd 100644 --- a/arm64-asm.c +++ b/arm64-asm.c @@ -293,17 +293,19 @@ static void parse_addr_operand(TCCState *s1, Operand *op) skip('['); reg = arm64_parse_regvar(tok); - if (reg >= 0 && reg < 32) { - op->reg = reg; - op->reg_tok = tok; + if (reg < 0 || reg >= 32) { + tcc_error("invalid register in address operand"); + return; + } + op->reg = reg; + op->reg_tok = tok; + next(); + /* Check for offset */ + if (tok == ',') { next(); - /* Check for offset */ - if (tok == ',') { + if (tok == '#' || tok == '@' || tok == '$') next(); - if (tok == '#' || tok == '@' || tok == '$') - next(); - asm_expr(s1, &op->e); - } + asm_expr(s1, &op->e); } skip(']'); if (tok == '!') {