Skip to content

Commit 2e44873

Browse files
committedJul 1, 2015
Inventory manager style cleanup and further checks
1 parent b2160bc commit 2e44873

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed
 

Diff for: ‎src/inventorymanager.cpp

+23-16
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
172172
Inventory *inv_from = mgr->getInventory(from_inv);
173173
Inventory *inv_to = mgr->getInventory(to_inv);
174174

175-
if(!inv_from){
176-
infostream<<"IMoveAction::apply(): FAIL: source inventory not found: "
177-
<<"from_inv=\""<<from_inv.dump()<<"\""
178-
<<", to_inv=\""<<to_inv.dump()<<"\""<<std::endl;
175+
if (!inv_from) {
176+
infostream << "IMoveAction::apply(): FAIL: source inventory not found: "
177+
<< "from_inv=\""<<from_inv.dump() << "\""
178+
<< ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
179179
return;
180180
}
181-
if(!inv_to){
182-
infostream<<"IMoveAction::apply(): FAIL: destination inventory not found: "
183-
<<"from_inv=\""<<from_inv.dump()<<"\""
184-
<<", to_inv=\""<<to_inv.dump()<<"\""<<std::endl;
181+
if (!inv_to) {
182+
infostream << "IMoveAction::apply(): FAIL: destination inventory not found: "
183+
<< "from_inv=\"" << from_inv.dump() << "\""
184+
<< ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
185185
return;
186186
}
187187

@@ -191,16 +191,16 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
191191
/*
192192
If a list doesn't exist or the source item doesn't exist
193193
*/
194-
if(!list_from){
195-
infostream<<"IMoveAction::apply(): FAIL: source list not found: "
196-
<<"from_inv=\""<<from_inv.dump()<<"\""
197-
<<", from_list=\""<<from_list<<"\""<<std::endl;
194+
if (!list_from) {
195+
infostream << "IMoveAction::apply(): FAIL: source list not found: "
196+
<< "from_inv=\"" << from_inv.dump() << "\""
197+
<< ", from_list=\"" << from_list << "\"" << std::endl;
198198
return;
199199
}
200-
if(!list_to){
201-
infostream<<"IMoveAction::apply(): FAIL: destination list not found: "
202-
<<"to_inv=\""<<to_inv.dump()<<"\""
203-
<<", to_list=\""<<to_list<<"\""<<std::endl;
200+
if (!list_to) {
201+
infostream << "IMoveAction::apply(): FAIL: destination list not found: "
202+
<< "to_inv=\""<<to_inv.dump() << "\""
203+
<< ", to_list=\"" << to_list << "\"" << std::endl;
204204
return;
205205
}
206206

@@ -246,6 +246,13 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
246246
move_somewhere = true;
247247
return;
248248
}
249+
250+
if ((u16)to_i > list_to->getSize()) {
251+
infostream << "IMoveAction::apply(): FAIL: destination index out of bounds: "
252+
<< "to_i=" << to_i
253+
<< ", size=" << list_to->getSize() << std::endl;
254+
return;
255+
}
249256
/*
250257
Do not handle rollback if both inventories are that of the same player
251258
*/

0 commit comments

Comments
 (0)
Please sign in to comment.