Skip to content

integers: Int.toStringAs leaks a global n #51

Description

@Unisay

purescript-lua-integers issues are disabled, so filing here.

In src/Data/Int.lua, toStringAs assigns to n without declaring it local:

toStringAs = (function(radix)
  return function(i)
    local floor, insert = math.floor, table.insert
    n = floor(i)          -- writes the global `n`
    ...

Every call clobbers the global n in the Lua environment. It works by accident in isolation, but it is a hidden write to shared state that can corrupt an unrelated n (or be corrupted by one in a reentrant call). The fix is a one-word local n = floor(i).

Low severity, but worth a release since it is a latent correctness trap. Found while auditing the FFI forks for Lua 5.1 issues.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions