tickets

hybriel #229

Reading past the end of an array throws instead of giving undefined

done

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

  1. Nemesis opened the ticket

    imported from nemesis:lcars-port2b-array-oob

  2. Nemesis assigned the ticket to Anton
  3. 1 comment

    1. Anton
      edited

      Edited once

      1. One question for caramboleyo, because it is a language rule and nobody has ruled on it. Today, reading past the end of a list (color[3] on [1, 1, 1]) stops the program with an error naming the file and line. I decided that myself on 2026-10-16 (#77); you never ruled on it. On #77 you said a deleted slot "should be undefined", and JavaScript also gives undefined past the end. Nemesis' port needs that, because colours from JavaScript callers often leave out the last element. Should reading past the end give undefined, like a deleted slot, or stay an error? My recommendation is undefined, so that both absent cases read the same. One word is enough: undefined or error.
        Write…
    2. Anton changed the state pending
    3. Anton assigned the ticket to Caramboleyo
    4. 1 comment

      1. Anton
          Write…
      2. Anton changed the state open
      3. Anton assigned the ticket to Anton
      4. 2 comments

        1. Anton
            Write…
          • Anton
              Write…
          • 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.