@@ -436,8 +436,7 @@ void InventoryList::deSerialize(std::istream &is)
436
436
u32 item_i = 0 ;
437
437
m_width = 0 ;
438
438
439
- for (;;)
440
- {
439
+ while (is.good ()) {
441
440
std::string line;
442
441
std::getline (is, line, ' \n ' );
443
442
@@ -447,14 +446,12 @@ void InventoryList::deSerialize(std::istream &is)
447
446
std::string name;
448
447
std::getline (iss, name, ' ' );
449
448
450
- if (name == " EndInventoryList" ) {
451
- break ;
452
- }
449
+ if (name == " EndInventoryList" )
450
+ return ;
453
451
454
452
// This is a temporary backwards compatibility fix
455
- if (name == " end" ) {
456
- break ;
457
- }
453
+ if (name == " end" )
454
+ return ;
458
455
459
456
if (name == " Width" ) {
460
457
iss >> m_width;
@@ -476,6 +473,14 @@ void InventoryList::deSerialize(std::istream &is)
476
473
m_items[item_i++].clear ();
477
474
}
478
475
}
476
+
477
+ // Contents given to deSerialize() were not terminated properly: throw error.
478
+
479
+ std::ostringstream ss;
480
+ ss << " Malformatted inventory list. list="
481
+ << m_name << " , read " << item_i << " of " << getSize ()
482
+ << " ItemStacks." << std::endl;
483
+ throw SerializationError (ss.str ());
479
484
}
480
485
481
486
InventoryList::InventoryList (const InventoryList &other)
@@ -859,8 +864,7 @@ void Inventory::deSerialize(std::istream &is)
859
864
{
860
865
clear ();
861
866
862
- for (;;)
863
- {
867
+ while (is.good ()) {
864
868
std::string line;
865
869
std::getline (is, line, ' \n ' );
866
870
@@ -869,14 +873,12 @@ void Inventory::deSerialize(std::istream &is)
869
873
std::string name;
870
874
std::getline (iss, name, ' ' );
871
875
872
- if (name == " EndInventory" ) {
873
- break ;
874
- }
876
+ if (name == " EndInventory" )
877
+ return ;
875
878
876
879
// This is a temporary backwards compatibility fix
877
- if (name == " end" ) {
878
- break ;
879
- }
880
+ if (name == " end" )
881
+ return ;
880
882
881
883
if (name == " List" ) {
882
884
std::string listname;
@@ -895,6 +897,13 @@ void Inventory::deSerialize(std::istream &is)
895
897
throw SerializationError (" invalid inventory specifier: " + name);
896
898
}
897
899
}
900
+
901
+ // Contents given to deSerialize() were not terminated properly: throw error.
902
+
903
+ std::ostringstream ss;
904
+ ss << " Malformatted inventory (damaged?). "
905
+ << m_lists.size () << " lists read." << std::endl;
906
+ throw SerializationError (ss.str ());
898
907
}
899
908
900
909
InventoryList * Inventory::addList (const std::string &name, u32 size)
0 commit comments