u32 item_i = 0;
m_width = 0;
- for(;;)
- {
+ while (is.good()) {
std::string line;
std::getline(is, line, '\n');
std::string name;
std::getline(iss, name, ' ');
- if (name == "EndInventoryList") {
- break;
- }
+ if (name == "EndInventoryList")
+ return;
// This is a temporary backwards compatibility fix
- if (name == "end") {
- break;
- }
+ if (name == "end")
+ return;
if (name == "Width") {
iss >> m_width;
m_items[item_i++].clear();
}
}
+
+ // Contents given to deSerialize() were not terminated properly: throw error.
+
+ std::ostringstream ss;
+ ss << "Malformatted inventory list. list="
+ << m_name << ", read " << item_i << " of " << getSize()
+ << " ItemStacks." << std::endl;
+ throw SerializationError(ss.str());
}
InventoryList::InventoryList(const InventoryList &other)
{
clear();
- for(;;)
- {
+ while (is.good()) {
std::string line;
std::getline(is, line, '\n');
std::string name;
std::getline(iss, name, ' ');
- if (name == "EndInventory") {
- break;
- }
+ if (name == "EndInventory")
+ return;
// This is a temporary backwards compatibility fix
- if (name == "end") {
- break;
- }
+ if (name == "end")
+ return;
if (name == "List") {
std::string listname;
throw SerializationError("invalid inventory specifier: " + name);
}
}
+
+ // Contents given to deSerialize() were not terminated properly: throw error.
+
+ std::ostringstream ss;
+ ss << "Malformatted inventory (damaged?). "
+ << m_lists.size() << " lists read." << std::endl;
+ throw SerializationError(ss.str());
}
InventoryList * Inventory::addList(const std::string &name, u32 size)
} catch (SettingNotFoundException &e) {}
}
- inventory.deSerialize(is);
+ try {
+ inventory.deSerialize(is);
+ } catch (SerializationError &e) {
+ errorstream << "Failed to deserialize player inventory. player_name="
+ << name << " " << e.what() << std::endl;
+ }
if (!inventory.getList("craftpreview") && inventory.getList("craftresult")) {
// Convert players without craftpreview