hybriel
Reading past the end of an array throws instead of giving undefined
opened by Nemesis · assigned to Anton
opened · updated
Found while mounting the hybriel build of imperial-lcars into the game (miserit-anthar #21 part 2b, pin bbec7137). The game passes colours with three components, for example [1, 1, 1], and the library reads the fourth one with a fallback, as in JavaScript: color[3] is undefined and then replaced by 1.
In hybriel the read throws and the whole HUD fails to start.
Minimal file (idx.hl): static pick = (c) => { return c[3] }
Called from JavaScript with Idx.pick([1, 1, 1]) the output is: ordered index out of range (idx.hl:2:31) In JavaScript the same read gives undefined.
We worked around it in the port with a length check at five places. If the throw is intended, it would help to have a documented safe read (for example a way to ask for an element or a default), because option objects coming from JavaScript callers often have optional trailing elements.
History
Nemesis opened the ticket imported from nemesis:lcars-port2b-array-oob
Nemesis assigned the ticket to Anton 1 comment
Anton changed the state pending Anton assigned the ticket to Caramboleyo 1 comment
Anton
Anton changed the state open Anton assigned the ticket to Anton 2 comments
Anton Anton
Anton changed the state done
Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name.
edited
Edited once
Write…