Skip to content

Commit

Permalink
Fix bad index in removevalues (#571)
Browse files Browse the repository at this point in the history
* Fix bad index in removevalues

When the table.remove call from split into its own reverse iterating loop, the table.remove call was still using the `k` variable from the old loop rather than the new `i` index.

* The for loop in removevalues should also break

To match previous behavior, which was correct, the reverse iteration should also `break` so it doesn't needlessly try to match the entry that shifted into that index. No behavior change, as that entry would have already been checked and not matched.

If the table only has one entry that is removed, this code would be indexing an empty table.

* Embed scripts into scripts.c

Run embed to inject fixes to removevalues
  • Loading branch information
billfreist authored Nov 6, 2024
1 parent c4e45e2 commit 0d54b85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/base/bake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
for i = #tbl, 1, -1 do
for _, pattern in ipairs(removes) do
if pattern == tbl[i] then
table.remove(tbl, k)
table.remove(tbl, i)
break
end
end
end
Expand Down
Loading

0 comments on commit 0d54b85

Please sign in to comment.