From c5df2938c5acb0c5797b3bdbb2127b83ff32121e Mon Sep 17 00:00:00 2001 From: yuanbo Date: Wed, 16 Feb 2022 10:41:24 +0800 Subject: [PATCH] fix: hc-gen segment fault when decompile empty array Signed-off-by: yuanbo --- tools/hc-gen/src/decompile_gen.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/hc-gen/src/decompile_gen.cpp b/tools/hc-gen/src/decompile_gen.cpp index ba936007..b8b82e99 100644 --- a/tools/hc-gen/src/decompile_gen.cpp +++ b/tools/hc-gen/src/decompile_gen.cpp @@ -72,15 +72,17 @@ int32_t DecompileGen::PrintArrayType(const std::shared_ptr& astObj) { WriteFile("["); auto arrayElement = astObj->Child(); - while (arrayElement->Next()) { + if (arrayElement != nullptr) { + while (arrayElement->Next()) { + if (PrintBaseType(arrayElement) != NOERR) { + return EOUTPUT; + } + WriteFile(", "); + arrayElement = arrayElement->Next(); + } if (PrintBaseType(arrayElement) != NOERR) { return EOUTPUT; } - WriteFile(", "); - arrayElement = arrayElement->Next(); - } - if (PrintBaseType(arrayElement) != NOERR) { - return EOUTPUT; } WriteFile("]"); return NOERR;