inseven / opolua

A compiled-OPL interpreter for iOS written in Lua
https://opolua.org
MIT License
12 stars 0 forks source link

Internal Error: memory.lua:46: Out of bounds: 16 len=15 #200

Closed jbmorley closed 2 years ago

jbmorley commented 2 years ago

Description

Internal error in Mancala immediately after clicking through the registration dialog.

Details

memory.lua:46: Out of bounds: 16 len=15 for [t=0, Temporary (0), Temporary (0), Temporary (1), Temporary (13), Temporary (2), Temporary (12), Temporary (3), Temporary (11), Temporary (4), Temporary (10), Temporary (5), Temporary (9), Temporary (6), Temporary (8), Temporary (7)]

MANCALA\SETUP:0000022E: 14 [ArrayDirectLeftSideInt] 0x00D8
stack traceback:
    [C]: in function 'error'
    memory.lua:46: in metamethod '__index'
    ops.lua:605: in function <ops.lua:600>
    (...tail calls...)
    runtime.lua:806: in function <runtime.lua:791>
    [C]: in function 'xpcall'
    runtime.lua:923: in method 'pcallProc'
    runtime.lua:1278: in function 'runtime.runOpo'
tomsci commented 2 years ago

It looks like this program is making assumptions about how drawable IDs are allocated and expects the first 14 gCREATEs it performs to return the exact IDs 2 through 15, which are used as indexes into WINLIST% (which is only declared with 15 elements). Our current impl happens to return 3 through 16 in this particular call pattern, so the last id results in an attempted array write to WINLIST%[16] which triggers the memory.lua error.

Programs really shouldn't be making assumptions like this, it's not a documented feature of the runtime how it allocates drawable IDs, but of course there are programs out there that do...

We can probably make our allocation strategy line up with this program's expectations.