Skip to content

Commit 0e07a71

Browse files
committedMar 24, 2013
Add more error checking to l_register_ore
1 parent 423d69b commit 0e07a71

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/scriptapi.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,16 @@ static int l_register_ore(lua_State *L)
704704
enum OreType oretype = (OreType)getenumfield(L, index,
705705
"ore_type", es_OreType, ORE_SCATTER);
706706
Ore *ore = createOre(oretype);
707+
if (!ore) {
708+
errorstream << "register_ore: ore_type "
709+
<< oretype << " not implemented";
710+
return 0;
711+
}
707712

708713
ore->ore_name = getstringfield_default(L, index, "ore", "");
709714
ore->wherein_name = getstringfield_default(L, index, "wherein", "");
710-
ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 0);
711-
ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 0);
715+
ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
716+
ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
712717
ore->clust_size = getintfield_default(L, index, "clust_size", 0);
713718
ore->height_min = getintfield_default(L, index, "height_min", 0);
714719
ore->height_max = getintfield_default(L, index, "height_max", 0);
@@ -720,6 +725,13 @@ static int l_register_ore(lua_State *L)
720725

721726
ore->noise = NULL;
722727

728+
if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) {
729+
errorstream << "register_ore: clust_scarcity and clust_num_ores"
730+
"must be greater than 0";
731+
delete ore;
732+
return 0;
733+
}
734+
723735
emerge->ores.push_back(ore);
724736

725737
verbosestream << "register_ore: ore '" << ore->ore_name

0 commit comments

Comments
 (0)
Please sign in to comment.