Skip to content

Commit

Permalink
moved 'start function' validation to parse phase; dead code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
soundandform committed Jan 30, 2020
1 parent 05ee45b commit 84ddf13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
14 changes: 4 additions & 10 deletions source/m3_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,21 +455,15 @@ M3Result InitStartFunc (IM3Module io_module)
{
M3Result result = m3Err_none;

if (io_module->startFunction >= 0) {
if ((u32)io_module->startFunction >= io_module->numFunctions) {
return "start function index out of bounds";
}
IM3Function function = &io_module->functions [io_module->startFunction];
if (not function) {
return "start function not found";
}
if (io_module->startFunction >= 0)
{
IM3Function function = & io_module->functions [io_module->startFunction];

if (not function->compiled)
{
_ (Compile_Function (function));
if (result)
function = NULL;
}

_ (m3_Call(function));
}

Expand Down
12 changes: 8 additions & 4 deletions source/m3_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ M3Result ParseSection_Start (IM3Module io_module, bytes_t i_bytes, cbytes_t i_
{
M3Result result = m3Err_none;

u32 startFunc;
_ (ReadLEB_u32 (& startFunc, & i_bytes, i_end)); m3log (parse, "** Start Function: %d", startFunc);

io_module->startFunction = startFunc;
u32 startFuncIndex;
_ (ReadLEB_u32 (& startFuncIndex, & i_bytes, i_end)); m3log (parse, "** Start Function: %d", startFunc);

if (startFuncIndex < io_module->numFunctions)
{
io_module->startFunction = startFuncIndex;
}
else result = "start function index out of bounds";

_catch: return result;
}
Expand Down

0 comments on commit 84ddf13

Please sign in to comment.