Issues found by Cppcheck 1.55

src/logic/widelands_geometry.h:127: (warning) Member variable 'FCoords::field' is not initialized in the constructor.
src/logic/widelands_geometry.h:137: (warning) Member variable 'FCoords::field' is not initialized in the constructor.
src/logic/world.h:48: (warning) Member variable 'Resource_Descr::m_is_detectable' is not initialized in the constructor.
src/logic/world.h:136: (style) The struct 'MapGenAreaInfo 'does not have a constructor but it has attributes. The attributes are not initialized which may cause bugs or undefined behavior.
src/logic/world.h:205: (style) The struct 'MapGenBobArea 'does not have a constructor but it has attributes. The attributes are not initialized which may cause bugs or undefined behavior.
src/logic/world.h:232: (style) The struct 'MapGenInfo 'does not have a constructor but it has attributes. The attributes are not initialized which may cause bugs or undefined behavior.
src/logic/field.h:61: (style) The struct 'Field 'does not have a constructor but it has attributes. The attributes are not initialized which may cause bugs or undefined behavior.
src/logic/productionsite.h:199: (warning) Member variable 'State::program' is not initialized in the constructor.
src/logic/player.h:140: (warning) Member variable 'Field::constructionsite' is not initialized in the constructor.
src/logic/player.h:140: (warning) Member variable 'Field::border' is not initialized in the constructor.
src/logic/player.h:140: (warning) Member variable 'Field::border_r' is not initialized in the constructor.
src/logic/player.h:140: (warning) Member variable 'Field::border_br' is not initialized in the constructor.
src/logic/player.h:140: (warning) Member variable 'Field::border_bl' is not initialized in the constructor.
src/ai/ai_help_structs.h:166: (warning) Member variable 'BuildableField::avoid_military' is not initialized in the constructor.
src/ai/ai_help_structs.h:166: (warning) Member variable 'BuildableField::enemy_nearby' is not initialized in the constructor.
src/io/basic_fileread.h:53: (warning) Member variable 'basic_FileRead::length' is not initialized in the constructor.
src/io/basic_filewrite.h:97: (error) Common realloc mistake: 'data' nulled but not freed upon failure
src/machdep.h:70: (error) Uninitialized variable: s
src/machdep.h:72: (error) Uninitialized variable: s
src/machdep.h:74: (error) Uninitialized variable: s
src/machdep.h:76: (error) Uninitialized variable: s
src/machdep.h:78: (error) Uninitialized variable: s
src/chat.cc:74: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/economy/flag.cc:87: (error) Uninitialized variable: state
src/economy/test/test_routing.cc:97] -> [src/economy/test/test_routing.cc:97: (style) Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
src/logic/playercommand.h:64: (warning) Member variable 'Cmd_Bulldoze::recurse' is not initialized in the constructor.
src/logic/playercommand.h:133: (warning) Member variable 'Cmd_BuildRoad::path' is not initialized in the constructor.
src/logic/playercommand.h:133: (warning) Member variable 'Cmd_BuildRoad::steps' is not initialized in the constructor.
src/graphic/render/gameview.cc:264: (error) Uninitialized variable: r_player_field
src/graphic/render/surface_sdl.cc:125: (style) Variable 'pix' is assigned a value that is never used
src/graphic/texture.cc:177: (error) Common realloc mistake: 'm_pixels' nulled but not freed upon failure
src/i18n.cc:159: (style) Variable 'alt_str' is assigned a value that is never used
src/io/dedicated_log.cc:46: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/io/dedicated_log.cc:76: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/io/dedicated_log.cc:163: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/io/dedicated_log.cc:166: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/io/dedicated_log.cc:200: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/io/filesystem/filesystem.cc:69: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'm_root' a value by passing the value to the constructor in the initialization list.
src/logic/battle.cc:40: (warning) Member variable 'Battle::m_last_attack_hits' is not initialized in the constructor.
src/logic/building.cc:521: (style) Statements following return, break, continue, goto or throw will never be executed.
src/logic/building.cc:533: (style) Statements following return, break, continue, goto or throw will never be executed.
src/logic/building.cc:292: (error) Uninitialized variable: state
src/logic/cmd_incorporate.h:31: (warning) Member variable 'Cmd_Incorporate::worker' is not initialized in the constructor.
src/logic/cmd_luacoroutine.h:31: (warning) Member variable 'Cmd_LuaCoroutine::m_cr' is not initialized in the constructor.
src/logic/game.cc:505: (style) Variable 'no_name' is not assigned a value
src/logic/game.cc:128: (warning) Member variable 'Game::m_replayreader' is not initialized in the constructor.
src/gamesettings.h:76: (warning) Member variable 'GameSettings::scenario' is not initialized in the constructor.
src/gamesettings.h:76: (warning) Member variable 'GameSettings::multiplayer' is not initialized in the constructor.
src/network/network.h:133: (style) The struct 'Deserializer 'does not have a constructor but it has attributes. The attributes are not initialized which may cause bugs or undefined behavior.
src/logic/game.cc:588: (style) Found obsolete function 'usleep'. POSIX.1-2001 declares usleep() function obsolete and POSIX.1-2008 removes it. It is recommended that new applications use the 'nanosleep' or 'setitimer' function.
src/logic/map.cc:1781: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/logic/map.cc:71: (warning) Member variable 'Map::m_filename' is not initialized in the constructor.
src/logic/map.cc:71: (warning) Member variable 'Map::m_author' is not initialized in the constructor.
src/logic/map.cc:71: (warning) Member variable 'Map::m_name' is not initialized in the constructor.
src/logic/map.cc:71: (warning) Member variable 'Map::m_description' is not initialized in the constructor.
src/logic/map.cc:629: (error) Common realloc mistake: 'm_starting_pos' nulled but not freed upon failure
src/logic/playercommand.cc:1547: (warning) Member variable 'Cmd_SetStockPolicy::m_isworker' is not initialized in the constructor.
src/logic/playercommand.cc:210: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'bi' a value by passing the value to the constructor in the initialization list.
src/logic/playercommand.cc:262: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'coords' a value by passing the value to the constructor in the initialization list.
src/logic/playercommand.cc:315: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'start' a value by passing the value to the constructor in the initialization list.
src/logic/replay.cc:182: (style) The second of the two statements can never be executed, and so should be removed.
src/logic/soldier.cc:312: (warning) Member variable 'Soldier::m_combat_walking' is not initialized in the constructor.
src/logic/soldier.cc:193: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/logic/world.cc:259: (style) Variable 'res_str' is assigned a value that is never used
src/map_generator.cc:457: (style) The scope of the variable 'landType' can be reduced. Warning: It can be unsafe to fix this message. Be careful. Especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x) { int i = 0; if (x) { // it's safe to move 'int i = 0' here for (int n = 0; n < 10; ++n) { // it is possible but not safe to move 'int i = 0' here do_something(&i); } } } When you see this message it is always safe to reduce the variable scope 1 level. src/map_io/widelands_map_player_names_and_tribes_data_packet.cc:96: (style) Unused variable: name
src/map_io/widelands_map_player_names_and_tribes_data_packet.cc:96: (style) Unused variable: tribe
src/map_io/widelands_map_players_view_data_packet.cc:846: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/map_io/widelands_map_players_view_data_packet.cc:858: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/map_io/widelands_map_players_view_data_packet.cc:869: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/map_io/widelands_map_players_view_data_packet.cc:871: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/map_io/widelands_map_players_view_data_packet.cc:873: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/map_io/widelands_map_players_view_data_packet.cc:504: (error) Memory leak: mod
src/map_io/widelands_map_players_view_data_packet.cc:556: (error) Memory leak: mod
src/map_io/widelands_map_players_view_data_packet.cc:580: (error) Memory leak: mod
src/map_io/widelands_map_players_view_data_packet.cc:744: (error) Uninitialized variable: csi
src/network/internet_gaming.cc:104: (portability) Found non reentrant function 'gethostbyname'. For threadsafe applications it is recommended to use the reentrant replacement function 'gethostbyname_r'
src/network/internet_gaming.cc:104: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function
src/network/netclient.cc:737: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. This means that you should only use 'auto_ptr' for pointers obtained with operator 'new'. This excludes arrays, which are allocated by operator 'new[]' and must be deallocated by operator 'delete[]'.
src/network/netclient.cc:822: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. This means that you should only use 'auto_ptr' for pointers obtained with operator 'new'. This excludes arrays, which are allocated by operator 'new[]' and must be deallocated by operator 'delete[]'.
src/network/nethost.cc:441: (style) Unused variable: name
src/network/nethost.cc:787: (style) Variable 'tips' is assigned a value that is never used
src/network/nethost.cc:2559: (style) Variable 'name' is assigned a value that is never used
src/network/nethost.cc:66: (warning) Member variable 'HostGameSettingsProvider::m_lua' is not initialized in the constructor.
src/network/nethost.cc:581: (warning) Member variable 'NetHostImpl::promoter' is not initialized in the constructor.
src/network/nethost.cc:581: (warning) Member variable 'NetHostImpl::game' is not initialized in the constructor.
src/network/nethost.cc:581: (warning) Member variable 'NetHostImpl::waiting' is not initialized in the constructor.
src/network/nethost.cc:581: (warning) Member variable 'NetHostImpl::syncreport_pending' is not initialized in the constructor.
src/network/nethost.cc:581: (warning) Member variable 'NetHostImpl::syncreport_arrived' is not initialized in the constructor.
src/network/nethost.cc:734: (style) Found obsolete function 'usleep'. POSIX.1-2001 declares usleep() function obsolete and POSIX.1-2008 removes it. It is recommended that new applications use the 'nanosleep' or 'setitimer' function.
src/network/nethost.cc:741: (style) Found obsolete function 'usleep'. POSIX.1-2001 declares usleep() function obsolete and POSIX.1-2008 removes it. It is recommended that new applications use the 'nanosleep' or 'setitimer' function.
src/network/nethost.cc:1120: (performance) Useless call of function 'substr' because it returns a copy of the object. Use operator= instead.
src/network/nethost.cc:711: (style) Variable 'needip' is assigned a value that is never used
src/scripting/c_utils.h:52: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_game.cc:463: (style) Variable 'title' is assigned a value that is never used
src/scripting/lua_game.cc:464: (style) Variable 'body' is assigned a value that is never used
src/scripting/lua_game.cc:985: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'm_name' a value by passing the value to the constructor in the initialization list.
src/scripting/lua_game.cc:150: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_game.cc:169: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_game.cc:989: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_game.cc:1009: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_game.cc:1019: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_game.cc:1034: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_map.cc:338: (style) Statements following return, break, continue, goto or throw will never be executed.
src/scripting/lua_map.cc:235: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_map.cc:1054: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_map.cc:1065: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_map.cc:2375: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_map.cc:2471: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/lua_map.cc:2493: (performance) The conversion from const char* as returned by c_str to std::string creates an unnecessary string copy. Solve that by directly passing the string.
src/scripting/pluto.cc:1333: (warning) Redundant assignment of "stacksize" to itself
src/scripting/pluto.cc:1001: (style) The scope of the variable 'sizep' can be reduced. Warning: It can be unsafe to fix this message. Be careful. Especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x) { int i = 0; if (x) { // it's safe to move 'int i = 0' here for (int n = 0; n < 10; ++n) { // it is possible but not safe to move 'int i = 0' here do_something(&i); } } } When you see this message it is always safe to reduce the variable scope 1 level. src/scripting/pluto.cc:1001: (style) The scope of the variable 'sizek' can be reduced. Warning: It can be unsafe to fix this message. Be careful. Especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x) { int i = 0; if (x) { // it's safe to move 'int i = 0' here for (int n = 0; n < 10; ++n) { // it is possible but not safe to move 'int i = 0' here do_something(&i); } } } When you see this message it is always safe to reduce the variable scope 1 level. src/sound/sound_handler.cc:58: (warning) Member variable 'Sound_Handler::m_egbase' is not initialized in the constructor.
src/text_parser.cc:106: (style) Unused variable: block_text
src/text_parser.cc:54: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'm_font_color' a value by passing the value to the constructor in the initialization list.
src/timestring.cc:34: (portability) Found non reentrant function 'localtime'. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'
src/ui_basic/checkbox.cc:145: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/ui_fsmenu/internet_lobby.cc:400: (portability) Found non reentrant function 'gethostbyname'. For threadsafe applications it is recommended to use the reentrant replacement function 'gethostbyname_r'
src/ui_fsmenu/internet_lobby.cc:400: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function
src/ui_fsmenu/internet_lobby.cc:312: (performance) Either inefficent or wrong usage of string::find. string::compare will be faster if string::find's result is compared with 0, because it will not scan the whole string. If your intention is to check that there are no findings in the string, you should compare with string::npos.
src/ui_fsmenu/mapselect.h:63: (warning) Member variable 'MapData::scenario' is not initialized in the constructor.
src/ui_fsmenu/launchMPG.cc:603: (performance) Either inefficent or wrong usage of string::find. string::compare will be faster if string::find's result is compared with 0, because it will not scan the whole string. If your intention is to check that there are no findings in the string, you should compare with string::npos.
src/ui_fsmenu/netsetup_lan.cc:157: (portability) Found non reentrant function 'gethostbyname'. For threadsafe applications it is recommended to use the reentrant replacement function 'gethostbyname_r'
src/ui_fsmenu/netsetup_lan.cc:157: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function
src/wlapplication.cc:1762: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/wlapplication.cc:1475: (style) Found obsolete function 'usleep'. POSIX.1-2001 declares usleep() function obsolete and POSIX.1-2008 removes it. It is recommended that new applications use the 'nanosleep' or 'setitimer' function.
src/wlapplication.cc:2284: (style) Variable 'name_length' is assigned a value that is never used
src/wui/fieldaction.cc:970: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/wui/game_debug_ui.cc:291: (style) 'else if' condition matches previous condition at line 289
src/wui/game_debug_ui.cc:293: (style) 'else if' condition matches previous condition at line 289
src/wui/interactive_player.cc:445: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/wui/interactive_spectator.cc:277: (style) Suspicious expression. Boolean result is used in bitwise operation. The ! operator and the comparison operators have higher precedence than bitwise operators. It is recommended that the expression is clarified with parentheses.
src/wui/military_box.cc:108: (style) The scope of the variable 'buf' can be reduced. Warning: It can be unsafe to fix this message. Be careful. Especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x) { int i = 0; if (x) { // it's safe to move 'int i = 0' here for (int n = 0; n < 10; ++n) { // it is possible but not safe to move 'int i = 0' here do_something(&i); } } } When you see this message it is always safe to reduce the variable scope 1 level. src/wui/military_box.cc:123: (style) The scope of the variable 'buf' can be reduced. Warning: It can be unsafe to fix this message. Be careful. Especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x) { int i = 0; if (x) { // it's safe to move 'int i = 0' here for (int n = 0; n < 10; ++n) { // it is possible but not safe to move 'int i = 0' here do_something(&i); } } } When you see this message it is always safe to reduce the variable scope 1 level. src/wui/overlay_manager.cc:28: (warning) Member variable 'Overlay_Manager::m_callback_data' is not initialized in the constructor.
src/wui/quicknavigation.cc:38: (performance) When an object of a class is created, the constructors of all member variables are called consecutivly in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'm_history_index' a value by passing the value to the constructor in the initialization list.