From: kwolekr Date: Sun, 24 Mar 2013 19:29:23 +0000 (-0400) Subject: Add more error checking to l_register_ore X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=0e07a7157f4865c26b4d7d0ba6fb12f1de59373c;p=zefram%2Fminetest%2Fminetest_engine.git Add more error checking to l_register_ore --- diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index ddffbb0b..80abffa2 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -704,11 +704,16 @@ static int l_register_ore(lua_State *L) enum OreType oretype = (OreType)getenumfield(L, index, "ore_type", es_OreType, ORE_SCATTER); Ore *ore = createOre(oretype); + if (!ore) { + errorstream << "register_ore: ore_type " + << oretype << " not implemented"; + return 0; + } ore->ore_name = getstringfield_default(L, index, "ore", ""); ore->wherein_name = getstringfield_default(L, index, "wherein", ""); - ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 0); - ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 0); + ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1); + ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1); ore->clust_size = getintfield_default(L, index, "clust_size", 0); ore->height_min = getintfield_default(L, index, "height_min", 0); ore->height_max = getintfield_default(L, index, "height_max", 0); @@ -720,6 +725,13 @@ static int l_register_ore(lua_State *L) ore->noise = NULL; + if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) { + errorstream << "register_ore: clust_scarcity and clust_num_ores" + "must be greater than 0"; + delete ore; + return 0; + } + emerge->ores.push_back(ore); verbosestream << "register_ore: ore '" << ore->ore_name