Skip to content

Commit

Permalink
Fix potential problem modifying a table during iteration
Browse files Browse the repository at this point in the history
This fixes a potential problem flagged up during review where one
should not add to a table whilst iterating over it. The link to
the mailing list discussion about this is:

http://lua-users.org/lists/lua-l/2005-09/msg00512.html
  • Loading branch information
Jessica Tallon committed Jun 26, 2017
1 parent efd24f7 commit 5488770
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/yang/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,17 @@ function data_printer_from_grammar(production)
-- Iterate over productions trying to translate to other statements. This
-- is used for example in choice statements raising the lower statements
-- in case blocks up to the level of the choice, in place of the choice.
local translated = {}
for keyword,production in pairs(productions) do
local translator = translators[production.type]
if translator ~= nil then
local statements = translator(keyword, production)
for k,v in pairs(statements) do productions[k] = v end
productions[keyword] = nil
for k,v in pairs(statements) do translated[k] = v end
else
translated[keyword] = production
end
end
productions = translated
if not order then
order = {}
for k,_ in pairs(productions) do table.insert(order, k) end
Expand Down

0 comments on commit 5488770

Please sign in to comment.