From: yu.dongliang <18588496441@163.com> Date: Fri, 1 Aug 2025 13:23:21 +0000 (+0800) Subject: fix: struct array run core dump X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=253e01ff2eba44cae1ca23bde2438082209fbd0d;p=scf.git fix: struct array run core dump --- diff --git a/examples/struct_array.c b/examples/struct_array.c new file mode 100644 index 0000000..06b6143 --- /dev/null +++ b/examples/struct_array.c @@ -0,0 +1,20 @@ +int printf(const char* fmt, ...); + +struct A { + int x; +}; + +struct B +{ + A a[2]; +}; + +B b = { + {{1}, {2}} +}; + +int main() +{ + printf("%d\n", b.a[0].x); + return 0; +} diff --git a/native/x64/scf_x64_inst.c b/native/x64/scf_x64_inst.c index be69b2e..9854380 100644 --- a/native/x64/scf_x64_inst.c +++ b/native/x64/scf_x64_inst.c @@ -1049,7 +1049,7 @@ static int _x64_inst_array_index(scf_native_t* ctx, scf_3ac_code_t* c, int lea_f return ret; } - if (vb->nb_dimentions > 1 || lea_flag) { + if (vb->nb_dimentions > 1 || (vb->type >= SCF_STRUCT && 0 == vb->nb_pointers) || lea_flag) { OpCode = x64_find_OpCode(SCF_X64_LEA, rd->bytes, rd->bytes, SCF_X64_E2G); } else { diff --git a/parse/scf_operator_handler_expr.c b/parse/scf_operator_handler_expr.c index d5f6437..62faa07 100644 --- a/parse/scf_operator_handler_expr.c +++ b/parse/scf_operator_handler_expr.c @@ -105,7 +105,7 @@ static int _scf_op_expr_array_index(scf_ast_t* ast, scf_node_t** nodes, int nb_n return -EINVAL; } - if (!v0->const_literal_flag) { + if (!v0->const_literal_flag && !v0->member_flag) { scf_loge("\n"); return -EINVAL; }