fix index out of bounds error when reading gems

develop
Myk Taylor 2023-04-10 23:07:18 -07:00
parent 970f7df6c2
commit 51047367f4
No known key found for this signature in database
3 changed files with 15 additions and 9 deletions

@ -42,6 +42,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `blueprint`: interpret saplings, shrubs, and twigs as floors instead of walls - `blueprint`: interpret saplings, shrubs, and twigs as floors instead of walls
- `combine`: fix error processing stockpiles with boundaries that extend outside of the map - `combine`: fix error processing stockpiles with boundaries that extend outside of the map
- `prospector`: display both "raw" Z levels and "cooked" elevations - `prospector`: display both "raw" Z levels and "cooked" elevations
- `stockpiles`: fix crash when importing settings for gems from other worlds
- `stockpiles`: allow numbers in saved stockpile filenames
## Misc Improvements ## Misc Improvements
- `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base game - `buildingplan`: items in the item selection dialog should now use the same item quality symbols as the base game

@ -62,7 +62,7 @@ local function assert_safe_name(name)
if not name or #name == 0 then if not name or #name == 0 then
qerror('name missing or empty') qerror('name missing or empty')
end end
if name:find('[^%a._]') then if name:find('[^%w._]') then
qerror('name can only contain numbers, letters, periods, and underscores') qerror('name can only contain numbers, letters, periods, and underscores')
end end
end end

@ -1848,7 +1848,7 @@ void StockpileSerializer::read_gems(DeserializeMode mode, const vector<string>&
unserialize_list_material("mats/rough", all, val, filters, gem_mat_is_allowed, unserialize_list_material("mats/rough", all, val, filters, gem_mat_is_allowed,
[&](const size_t& idx) -> const string& { return bgems.rough_mats(idx); }, [&](const size_t& idx) -> const string& { return bgems.rough_mats(idx); },
bgems.rough_mats_size(),pgems.rough_mats); bgems.rough_mats_size(), pgems.rough_mats);
unserialize_list_material("mats/cut", all, val, filters, gem_cut_mat_is_allowed, unserialize_list_material("mats/cut", all, val, filters, gem_cut_mat_is_allowed,
[&](const size_t& idx) -> const string& { return bgems.cut_mats(idx); }, [&](const size_t& idx) -> const string& { return bgems.cut_mats(idx); },
@ -1871,13 +1871,17 @@ void StockpileSerializer::read_gems(DeserializeMode mode, const vector<string>&
return; return;
} else { } else {
MaterialInfo mi; MaterialInfo mi;
for (size_t i = 0; i < builtin_size; ++i) { for (int i = 0; i < (int)builtin_size; ++i) {
string id = bgems.rough_other_mats(i); if (i < bgems.rough_other_mats_size()) {
if (mi.find(id) && mi.isValid() && size_t(mi.type) < builtin_size) string id = bgems.rough_other_mats(i);
set_filter_elem("other/rough", filters, val, id, mi.type, pgems.rough_other_mats.at(mi.type)); if (mi.find(id) && mi.isValid() && size_t(mi.type) < builtin_size)
id = bgems.cut_other_mats(i); set_filter_elem("other/rough", filters, val, id, mi.type, pgems.rough_other_mats.at(mi.type));
if (mi.find(id) && mi.isValid() && size_t(mi.type) < builtin_size) }
set_filter_elem("other/cut", filters, val, id, mi.type, pgems.cut_other_mats.at(mi.type)); if (i < bgems.cut_other_mats_size()) {
string id = bgems.cut_other_mats(i);
if (mi.find(id) && mi.isValid() && size_t(mi.type) < builtin_size)
set_filter_elem("other/cut", filters, val, id, mi.type, pgems.cut_other_mats.at(mi.type));
}
} }
} }
}); });