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 +++++++------------ src/script/common/c_content.h | 4 ++-- src/script/lua_api/l_item.cpp | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/script') 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); diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 949b136eb..c701c0384 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -86,8 +86,8 @@ ToolCapabilities read_tool_capabilities (lua_State *L, int table); void push_tool_capabilities (lua_State *L, const ToolCapabilities &prop); -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); void read_object_properties (lua_State *L, int index, ObjectProperties *prop, IItemDefManager *idef); diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 2d32093a7..0e4fc4ef0 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -526,7 +526,7 @@ int ModApiItemMod::l_register_item_raw(lua_State *L) def.node_placement_prediction = "__default"; // Read the item definition - def = read_item_definition(L, table, def); + read_item_definition(L, table, def, def); // Default to having client-side placement prediction for nodes // ("" in item definition sets it off) -- cgit v1.2.3