diff options
author | Anthony Zhang <azhang9@gmail.com> | 2013-06-22 15:43:58 -0400 |
---|---|---|
committer | Anthony Zhang <azhang9@gmail.com> | 2013-06-22 15:43:58 -0400 |
commit | 96011bc71816b5e9eb2cc6c86f009198dfb1146c (patch) | |
tree | a3ded974dcfc8aca8f6b9837e5a4d571a84e680d /mesecons_extrawires | |
parent | ec63bd3abfdca2a77b7945834a9b37f7533a4e27 (diff) | |
download | mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar.gz mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar.bz2 mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.tar.xz mesecons-96011bc71816b5e9eb2cc6c86f009198dfb1146c.zip |
Audit code for possible nil value indexing with unregistered nodes.
Diffstat (limited to 'mesecons_extrawires')
-rw-r--r-- | mesecons_extrawires/depends.txt | 1 | ||||
-rw-r--r-- | mesecons_extrawires/vertical.lua | 32 |
2 files changed, 13 insertions, 20 deletions
diff --git a/mesecons_extrawires/depends.txt b/mesecons_extrawires/depends.txt index acaa924..aca967d 100644 --- a/mesecons_extrawires/depends.txt +++ b/mesecons_extrawires/depends.txt @@ -1 +1,2 @@ +default mesecons diff --git a/mesecons_extrawires/vertical.lua b/mesecons_extrawires/vertical.lua index 39b5417..3274c1a 100644 --- a/mesecons_extrawires/vertical.lua +++ b/mesecons_extrawires/vertical.lua @@ -34,31 +34,23 @@ local brules = local vertical_updatepos = function (pos) local node = minetest.env:get_node(pos) - if minetest.registered_nodes[node.name].is_vertical_conductor then + if minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].is_vertical_conductor then local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1])) local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2])) local namestate = minetest.registered_nodes[node.name].vertical_conductor_state - -- above and below: vertical mesecon - if minetest.registered_nodes[node_above.name].is_vertical_conductor - and minetest.registered_nodes[node_below.name].is_vertical_conductor then - minetest.env:add_node (pos, - {name = "mesecons_extrawires:vertical_"..namestate}) - - -- above only: bottom - elseif minetest.registered_nodes[node_above.name].is_vertical_conductor - and not minetest.registered_nodes[node_below.name].is_vertical_conductor then - minetest.env:add_node (pos, - {name = "mesecons_extrawires:vertical_bottom_"..namestate}) - - -- below only: top - elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor - and minetest.registered_nodes[node_below.name].is_vertical_conductor then - minetest.env:add_node (pos, - {name = "mesecons_extrawires:vertical_top_"..namestate}) + local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor + local below = minetest.registered_nodes[node_below.name] and minetest.registered_nodes[node_below.name].is_vertical_conductor + + if above and below then -- above and below: vertical mesecon + minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_"..namestate}) + elseif above and not below then -- above only: bottom + minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_bottom_"..namestate}) + elseif not above and below then -- below only: top + minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_top_"..namestate}) else -- no vertical wire above, no vertical wire below: use default wire - minetest.env:add_node (pos, - {name = "mesecons_extrawires:vertical_"..namestate}) + minetest.env:add_node (pos, {name = "mesecons_extrawires:vertical_"..namestate}) end end end |