Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f55ac3

Browse files
authoredApr 25, 2017
Fix various points reported by cppcheck (#5656)
* Fix various performance issues reported by cppcheck + code style (CI) * Make CI happy with code style on master * guiFileSelectMenu: remove useless includes * some performance fixes pointed by cppcheck * remove some useless casts * TextDest: remove unused setFormSpec function * Fix various iterator post-increment reported by cppcheck
1 parent af96309 commit 7f55ac3

13 files changed

+27
-39
lines changed
 

Diff for: ‎src/game.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,6 @@ class NodeMetadataFormSource: public IFormSource
202202

203203
return meta->getString("formspec");
204204
}
205-
std::string resolveText(std::string str)
206-
{
207-
NodeMetadata *meta = m_map->getNodeMetadata(m_p);
208-
209-
if (!meta)
210-
return str;
211-
212-
return meta->resolveString(str);
213-
}
214205

215206
ClientMap *m_map;
216207
v3s16 m_p;

Diff for: ‎src/guiFormSpecMenu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class IFormSource
6969
virtual ~IFormSource(){}
7070
virtual std::string getForm() = 0;
7171
// Fill in variables in field text
72-
virtual std::string resolveText(std::string str){ return str; }
72+
virtual std::string resolveText(const std::string &str) { return str; }
7373
};
7474

7575
class GUIFormSpecMenu : public GUIModalMenu

Diff for: ‎src/map_settings_manager.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525

2626
#include "map_settings_manager.h"
2727

28-
MapSettingsManager::MapSettingsManager(
29-
Settings *user_settings, const std::string &map_meta_path)
28+
MapSettingsManager::MapSettingsManager(Settings *user_settings,
29+
const std::string &map_meta_path):
30+
mapgen_params(NULL),
31+
m_map_meta_path(map_meta_path),
32+
m_map_settings(new Settings()),
33+
m_user_settings(user_settings)
3034
{
31-
m_map_meta_path = map_meta_path;
32-
m_user_settings = user_settings;
33-
m_map_settings = new Settings;
34-
mapgen_params = NULL;
35-
3635
assert(m_user_settings != NULL);
3736
}
3837

Diff for: ‎src/nodedef.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1318,22 +1318,21 @@ void CNodeDefManager::removeNode(const std::string &name)
13181318

13191319
// Erase node content from all groups it belongs to
13201320
for (UNORDERED_MAP<std::string, GroupItems>::iterator iter_groups =
1321-
m_group_to_items.begin();
1322-
iter_groups != m_group_to_items.end();) {
1321+
m_group_to_items.begin(); iter_groups != m_group_to_items.end();) {
13231322
GroupItems &items = iter_groups->second;
13241323
for (GroupItems::iterator iter_groupitems = items.begin();
13251324
iter_groupitems != items.end();) {
13261325
if (iter_groupitems->first == id)
13271326
items.erase(iter_groupitems++);
13281327
else
1329-
iter_groupitems++;
1328+
++iter_groupitems;
13301329
}
13311330

13321331
// Check if group is empty
13331332
if (items.size() == 0)
13341333
m_group_to_items.erase(iter_groups++);
13351334
else
1336-
iter_groups++;
1335+
++iter_groups;
13371336
}
13381337
}
13391338

Diff for: ‎src/script/cpp_api/s_async.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ AsyncEngine::~AsyncEngine()
4646

4747
// Request all threads to stop
4848
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
49-
it != workerThreads.end(); it++) {
49+
it != workerThreads.end(); ++it) {
5050
(*it)->stop();
5151
}
5252

5353

5454
// Wake up all threads
5555
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
56-
it != workerThreads.end(); it++) {
56+
it != workerThreads.end(); ++it) {
5757
jobQueueCounter.post();
5858
}
5959

6060
// Wait for threads to finish
6161
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
62-
it != workerThreads.end(); it++) {
62+
it != workerThreads.end(); ++it) {
6363
(*it)->wait();
6464
}
6565

6666
// Force kill all threads
6767
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
68-
it != workerThreads.end(); it++) {
68+
it != workerThreads.end(); ++it) {
6969
delete *it;
7070
}
7171

@@ -205,7 +205,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) {
205205
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
206206
{
207207
for (UNORDERED_MAP<std::string, lua_CFunction>::iterator it = functionList.begin();
208-
it != functionList.end(); it++) {
208+
it != functionList.end(); ++it) {
209209
lua_pushstring(L, it->first.c_str());
210210
lua_pushcfunction(L, it->second);
211211
lua_settable(L, top);

Diff for: ‎src/script/cpp_api/s_node.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
263263
lua_pushstring(L, formname.c_str()); // formname
264264
lua_newtable(L); // fields
265265
StringMap::const_iterator it;
266-
for (it = fields.begin(); it != fields.end(); it++) {
266+
for (it = fields.begin(); it != fields.end(); ++it) {
267267
const std::string &name = it->first;
268268
const std::string &value = it->second;
269269
lua_pushstring(L, name.c_str());

Diff for: ‎src/script/lua_api/l_client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int ModApiClient::l_get_player_names(lua_State *L)
8383
int newTable = lua_gettop(L);
8484
int index = 1;
8585
std::list<std::string>::const_iterator iter;
86-
for (iter = plist.begin(); iter != plist.end(); iter++) {
86+
for (iter = plist.begin(); iter != plist.end(); ++iter) {
8787
lua_pushstring(L, (*iter).c_str());
8888
lua_rawseti(L, newTable, index);
8989
index++;

Diff for: ‎src/script/lua_api/l_craft.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static void push_craft_recipe(lua_State *L, IGameDef *gdef,
414414

415415
lua_newtable(L); // items
416416
std::vector<ItemStack>::const_iterator iter = input.items.begin();
417-
for (u16 j = 1; iter != input.items.end(); iter++, j++) {
417+
for (u16 j = 1; iter != input.items.end(); ++iter, j++) {
418418
if (iter->empty())
419419
continue;
420420
lua_pushstring(L, iter->name.c_str());

Diff for: ‎src/script/lua_api/l_env.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
534534
ScriptApiBase *script = getScriptApiBase(L);
535535
lua_createtable(L, ids.size(), 0);
536536
std::vector<u16>::const_iterator iter = ids.begin();
537-
for(u32 i = 0; iter != ids.end(); iter++) {
537+
for(u32 i = 0; iter != ids.end(); ++iter) {
538538
ServerActiveObject *obj = env->getActiveObject(*iter);
539539
// Insert object reference into table
540540
script->objectrefGetOrCreate(L, obj);
@@ -985,8 +985,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
985985
lua_newtable(L);
986986
int top = lua_gettop(L);
987987
unsigned int index = 1;
988-
for (std::vector<v3s16>::iterator i = path.begin(); i != path.end();i++)
989-
{
988+
for (std::vector<v3s16>::iterator i = path.begin(); i != path.end(); ++i) {
990989
lua_pushnumber(L,index);
991990
push_v3s16(L, *i);
992991
lua_settable(L, top);

Diff for: ‎src/script/lua_api/l_mainmenu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ int ModApiMainMenu::l_get_games(lua_State *L)
297297
int table2 = lua_gettop(L);
298298
int internal_index=1;
299299
for (std::set<std::string>::iterator iter = games[i].addon_mods_paths.begin();
300-
iter != games[i].addon_mods_paths.end(); iter++) {
300+
iter != games[i].addon_mods_paths.end(); ++iter) {
301301
lua_pushnumber(L,internal_index);
302302
lua_pushstring(L,(*iter).c_str());
303303
lua_settable(L, table2);

Diff for: ‎src/script/lua_api/l_nodemeta.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void NodeMetaRef::handleToTable(lua_State *L, Metadata *_meta)
107107
if (inv) {
108108
std::vector<const InventoryList *> lists = inv->getLists();
109109
for(std::vector<const InventoryList *>::const_iterator
110-
i = lists.begin(); i != lists.end(); i++) {
110+
i = lists.begin(); i != lists.end(); ++i) {
111111
push_inventory_list(L, inv, (*i)->getName().c_str());
112112
lua_setfield(L, -2, (*i)->getName().c_str());
113113
}

Diff for: ‎src/script/lua_api/l_server.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int ModApiServer::l_get_player_privs(lua_State *L)
103103
int table = lua_gettop(L);
104104
std::set<std::string> privs_s = server->getPlayerEffectivePrivs(name);
105105
for(std::set<std::string>::const_iterator
106-
i = privs_s.begin(); i != privs_s.end(); i++){
106+
i = privs_s.begin(); i != privs_s.end(); ++i){
107107
lua_pushboolean(L, true);
108108
lua_setfield(L, table, i->c_str());
109109
}
@@ -417,7 +417,7 @@ int ModApiServer::l_get_modnames(lua_State *L)
417417
// Package them up for Lua
418418
lua_createtable(L, modlist.size(), 0);
419419
std::vector<std::string>::iterator iter = modlist.begin();
420-
for (u16 i = 0; iter != modlist.end(); iter++) {
420+
for (u16 i = 0; iter != modlist.end(); ++iter) {
421421
lua_pushstring(L, iter->c_str());
422422
lua_rawseti(L, -2, ++i);
423423
}

Diff for: ‎src/util/thread.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class GetRequest {
8383
GetRequest() {}
8484
~GetRequest() {}
8585

86-
GetRequest(Key a_key) {
87-
key = a_key;
86+
GetRequest(const Key &a_key): key(a_key)
87+
{
8888
}
8989

9090
Key key;
@@ -106,7 +106,7 @@ class RequestQueue {
106106
return m_queue.empty();
107107
}
108108

109-
void add(Key key, Caller caller, CallerData callerdata,
109+
void add(const Key &key, Caller caller, CallerData callerdata,
110110
ResultQueue<Key, T, Caller, CallerData> *dest)
111111
{
112112
typename std::deque<GetRequest<Key, T, Caller, CallerData> >::iterator i;

0 commit comments

Comments
 (0)
Please sign in to comment.