Skip to content

Commit 84ddf13

Browse files
committedJan 30, 2020
moved 'start function' validation to parse phase; dead code cleanup
1 parent 05ee45b commit 84ddf13

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed
 

‎source/m3_env.c

+4-10
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,15 @@ M3Result InitStartFunc (IM3Module io_module)
455455
{
456456
M3Result result = m3Err_none;
457457

458-
if (io_module->startFunction >= 0) {
459-
if ((u32)io_module->startFunction >= io_module->numFunctions) {
460-
return "start function index out of bounds";
461-
}
462-
IM3Function function = &io_module->functions [io_module->startFunction];
463-
if (not function) {
464-
return "start function not found";
465-
}
458+
if (io_module->startFunction >= 0)
459+
{
460+
IM3Function function = & io_module->functions [io_module->startFunction];
466461

467462
if (not function->compiled)
468463
{
469464
_ (Compile_Function (function));
470-
if (result)
471-
function = NULL;
472465
}
466+
473467
_ (m3_Call(function));
474468
}
475469

‎source/m3_parse.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ M3Result ParseSection_Start (IM3Module io_module, bytes_t i_bytes, cbytes_t i_
234234
{
235235
M3Result result = m3Err_none;
236236

237-
u32 startFunc;
238-
_ (ReadLEB_u32 (& startFunc, & i_bytes, i_end)); m3log (parse, "** Start Function: %d", startFunc);
239-
240-
io_module->startFunction = startFunc;
237+
u32 startFuncIndex;
238+
_ (ReadLEB_u32 (& startFuncIndex, & i_bytes, i_end)); m3log (parse, "** Start Function: %d", startFunc);
239+
240+
if (startFuncIndex < io_module->numFunctions)
241+
{
242+
io_module->startFunction = startFuncIndex;
243+
}
244+
else result = "start function index out of bounds";
241245

242246
_catch: return result;
243247
}

0 commit comments

Comments
 (0)
Please sign in to comment.