Skip to content

Engine internals don't use local — calling re_* can clobber caller globals with common names (c, pos, n, ranges, ...) #5

Description

@InauguralPhysicist

EigenScript's name is expr updates an existing OUTER binding when one exists. The engine's internal functions (lib/regex_parse.eigs, lib/regex_compile.eigs, lib/regex_vm.eigs, and the older API functions in lib/regex.eigs) assign working variables without localc, pos, n, ranges, parts, branches, results, out, i, j, …

A user script that has a module-level variable with any of those names and then calls re_compile / re_search gets it silently overwritten. Example shape:

load_file of "lib/regex.eigs"
pos is 42
prog is re_compile of "[a-z]+"
r is re_find_all of [prog, "abc"]
print of pos    # no longer 42

The new code from #4 (re_replace, lib/regex_compat.eigs) already uses local throughout; this issue is the mechanical pass over the pre-existing functions. for-loop variables are already safe (loop scope); loop while counters and accumulators are not.

Fix: add local to the first assignment of every function-internal variable across the four lib files; suite must stay 347/347.

Metadata

Metadata

Assignees

No one assigned

    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