From f3fe62a0bf9e775b3e6e838f104ab605a2238792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Wed, 19 Apr 2017 23:02:07 +0200 Subject: Fix various copy instead of const ref reported by cppcheck (#5615) * Also remove InventoryList::peekItem unused function * Fix some post increment to preincrement reported by cppcheck --- src/script/common/c_content.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/script/common/c_content.cpp') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index bcae874b9..8dfb851e6 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -43,15 +43,12 @@ struct EnumString es_TileAnimationType[] = }; /******************************************************************************/ -ItemDefinition read_item_definition(lua_State* L,int index, - ItemDefinition default_def) +void read_item_definition(lua_State* L, int index, + const ItemDefinition &default_def, ItemDefinition &def) { - if(index < 0) + if (index < 0) index = lua_gettop(L) + 1 + index; - // Read the item definition - ItemDefinition def = default_def; - def.type = (ItemType)getenumfield(L, index, "type", es_ItemType, ITEM_NONE); getstringfield(L, index, "name", def.name); @@ -118,8 +115,6 @@ ItemDefinition read_item_definition(lua_State* L,int index, // "" = no prediction getstringfield(L, index, "node_placement_prediction", def.node_placement_prediction); - - return def; } /******************************************************************************/ @@ -873,7 +868,7 @@ void push_tool_capabilities(lua_State *L, lua_newtable(L); // For each groupcap for (ToolGCMap::const_iterator i = toolcap.groupcaps.begin(); - i != toolcap.groupcaps.end(); i++) { + i != toolcap.groupcaps.end(); ++i) { // Create groupcap table lua_newtable(L); const std::string &name = i->first; @@ -881,7 +876,7 @@ void push_tool_capabilities(lua_State *L, // Create subtable "times" lua_newtable(L); for (UNORDERED_MAP::const_iterator - i = groupcap.times.begin(); i != groupcap.times.end(); i++) { + i = groupcap.times.begin(); i != groupcap.times.end(); ++i) { lua_pushinteger(L, i->first); lua_pushnumber(L, i->second); lua_settable(L, -3); @@ -900,7 +895,7 @@ void push_tool_capabilities(lua_State *L, lua_newtable(L); // For each damage group for (DamageGroup::const_iterator i = toolcap.damageGroups.begin(); - i != toolcap.damageGroups.end(); i++) { + i != toolcap.damageGroups.end(); ++i) { // Create damage group table lua_pushinteger(L, i->second); lua_setfield(L, -2, i->first.c_str()); @@ -939,7 +934,7 @@ void read_inventory_list(lua_State *L, int tableindex, InventoryList *invlist = inv->addList(name, listsize); int index = 0; for(std::vector::const_iterator - i = items.begin(); i != items.end(); i++){ + i = items.begin(); i != items.end(); ++i){ if(forcesize != -1 && index == forcesize) break; invlist->changeItem(index, *i); -- cgit v1.2.3