Skip to content

Lua: a missing string in a hashtable is the null string, "" - #1437

Merged
Frotty merged 2 commits into
masterfrom
lua-loadstr-empty
Oct 12, 2026
Merged

Frotty merged 2 commits into
masterfrom
lua-loadstr-empty

Conversation

@Frotty

@Frotty Frotty commented Oct 12, 2026

Copy link
Copy Markdown
Member

On Lua, Wurst's null string is "" (EliminateLocalTypes), but the emulated LoadStr answered nil when nothing was stored. That nil then reached the game's natives, which raise on it. StringLength(LoadStr(h, 1, 1)) stopped the thread with "bad argument #1 to 'StringLength' (string expected, got nil)", and LoadStr(h, 1, 1) == null was false.

Measured on the 3.0.0 client, with a real nil (a missing LoadStr) passed to each native:

  • Every string native probed raises on nil in the game's Lua: StringLength, SubString, StringCase, S2I, S2R, StringHash, GetLocalizedString, BlzSetUnitName, SetTextTagText, BlzFrameSetText and DisplayTextToPlayer.
  • Where Jass answers null, the game's Lua natives answer "": SubString past the end, any SubString of "", and StringCase("").

So "" is the null string the game's Lua natives use themselves. Making Wurst's null nil instead would have to guard every string argument of a native: 752 sites in one real map and 550 in another, after the existing analysis. It would still not match Jass, because the natives return "" where Jass returns null.

What changes

  • The emulated LoadStr answers "" when nothing is stored, both printed in place (LuaHashtableTranslation) and through its helper (LuaNatives), including a missing parent key, a flushed hashtable and a null hashtable. That adds one or "" on the string load.
  • LuaNativeLowering.neverNil knows that LoadStr never answers nil, so a concatenation with it needs no guard of its own.
  • docs/WC3_RUNTIME.md records the measurements and the convention: null == "" is true on Lua and false on Jass. Matching Jass would mean wrapping every native that returns a string.

Tests

  • LuaHashtableTests checks that StringLength(LoadStr(...)) is 0 and that LoadStr(...) == null holds, on every path (absent parent key, absent child key, flushed hashtable, null hashtable, and the helper), on the interpreter, Jass and Lua.
    • Without the fix the Lua run stops with "attempt to get length of a nil value".
  • The shape assertions in LuaHashtableTests and LuaNativesTests are updated.
  • LuaHashtableTests, LuaNativesTests, LuaTranslationTests, LuaBackendAuditTests and CompiletimeHashtableTests pass locally.

Also measured: in Jass, BlzSetUnitName(u, null) crashes the client. This is recorded in the doc and not changed here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T09:50:10.755045Z 8a0c246 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14a8ecf1f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 8a0c246fc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty merged commit 0ef3c63 into master Oct 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant