From 0a6982f4041f43d571bd2690f148ff369f2d8038 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 20 Apr 2012 13:30:37 +0400 Subject: [PATCH] Enable warnings correctly on linux and fix a lot of them. --- CMakeLists.txt | 2 +- depends/protobuf/CMakeLists.txt | 2 ++ library/Console-linux.cpp | 11 ++++++----- library/DataDefs.cpp | 8 ++++---- library/LuaApi.cpp | 1 + library/LuaTypes.cpp | 29 ----------------------------- library/RemoteTools.cpp | 7 +++++-- library/TileTypes.cpp | 2 ++ library/include/DataDefs.h | 4 ++-- library/include/RemoteTools.h | 2 +- library/include/modules/Windows.h | 12 ++++++------ library/modules/Constructions.cpp | 4 ++-- library/modules/Engravings.cpp | 4 ++-- library/modules/Gui.cpp | 2 +- library/modules/Items.cpp | 3 +++ library/modules/Maps.cpp | 17 +++++++++++------ library/modules/Materials.cpp | 10 +++++----- library/modules/Units.cpp | 2 +- library/modules/Vegetation.cpp | 4 ++-- library/modules/Windows.cpp | 2 +- library/xml | 2 +- plugins/burrows.cpp | 10 +++++----- plugins/jobutils.cpp | 4 ++-- plugins/mapexport/mapexport.cpp | 6 +++--- plugins/workflow.cpp | 6 ++++++ 25 files changed, 75 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e83f20f54..d16390c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ OPTION(BUILD_PLUGINS "Build the plugins." ON) # enable C++11 features IF(UNIX) add_definitions(-DLINUX_BUILD) - SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -Wall -Wno-unused-variable") SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -m32 -march=i686 -mtune=generic -std=c++0x") SET(CMAKE_C_FLAGS "-fvisibility=hidden -m32 -march=i686 -mtune=generic") ENDIF() diff --git a/depends/protobuf/CMakeLists.txt b/depends/protobuf/CMakeLists.txt index f4a3b6d19..92504f059 100644 --- a/depends/protobuf/CMakeLists.txt +++ b/depends/protobuf/CMakeLists.txt @@ -200,6 +200,8 @@ google/protobuf/compiler/zip_writer.cc LIST(APPEND LIBPROTOBUF_FULL_SRCS ${LIBPROTOBUF_LITE_SRCS}) +SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wno-sign-compare") + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(PROTOBUF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp index 9a0905647..3c0ad8938 100644 --- a/library/Console-linux.cpp +++ b/library/Console-linux.cpp @@ -163,6 +163,7 @@ namespace DFHack return false; return true; } + return false; } public: @@ -489,7 +490,7 @@ namespace DFHack { right_arrow: /* right arrow */ - if (raw_cursor != raw_buffer.size()) + if (size_t(raw_cursor) != raw_buffer.size()) { raw_cursor++; prompt_refresh(); @@ -510,7 +511,7 @@ namespace DFHack history_index = 0; break; } - else if (history_index >= history.size()) + else if (size_t(history_index) >= history.size()) { history_index = history.size()-1; break; @@ -545,7 +546,7 @@ namespace DFHack if (seq[1] == '3' && seq2 == '~' ) { // delete - if (raw_buffer.size() > 0 && raw_cursor < raw_buffer.size()) + if (raw_buffer.size() > 0 && size_t(raw_cursor) < raw_buffer.size()) { raw_buffer.erase(raw_cursor,1); prompt_refresh(); @@ -555,11 +556,11 @@ namespace DFHack } break; default: - if (raw_buffer.size() == raw_cursor) + if (raw_buffer.size() == size_t(raw_cursor)) { raw_buffer.append(1,c); raw_cursor++; - if (plen+raw_buffer.size() < get_columns()) + if (plen+raw_buffer.size() < size_t(get_columns())) { /* Avoid a full update of the line in the * trivial case. */ diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index 062635182..061110ecc 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -98,7 +98,7 @@ std::vector compound_identity::top_scope; compound_identity::compound_identity(size_t size, TAllocateFn alloc, compound_identity *scope_parent, const char *dfhack_name) - : constructed_identity(size, alloc), scope_parent(scope_parent), dfhack_name(dfhack_name) + : constructed_identity(size, alloc), dfhack_name(dfhack_name), scope_parent(scope_parent) { next = list; list = this; } @@ -146,8 +146,8 @@ enum_identity::enum_identity(size_t size, const char *const *keys, const void *attrs, struct_identity *attr_type) : compound_identity(size, NULL, scope_parent, dfhack_name), - first_item_value(first_item_value), last_item_value(last_item_value), - keys(keys), base_type(base_type), attrs(attrs), attr_type(attr_type) + keys(keys), first_item_value(first_item_value), last_item_value(last_item_value), + base_type(base_type), attrs(attrs), attr_type(attr_type) { } @@ -382,7 +382,7 @@ int DFHack::findEnumItem(const std::string &name, int size, const char *const *i void DFHack::flagarrayToString(std::vector *pvec, const void *p, int bytes, int base, int size, const char *const *items) { - for (unsigned i = 0; i < bytes*8; i++) { + for (int i = 0; i < bytes*8; i++) { int value = getBitfieldField(p, i, 1); if (value) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 5f2195760..ccd057c9c 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -353,6 +353,7 @@ static void push_matinfo(lua_State *state, MaterialInfo &info) case MaterialInfo::Plant: id = "plant"; break; case MaterialInfo::Creature: id = "creature"; break; case MaterialInfo::Inorganic: id = "inorganic"; break; + default: break; } lua_pushstring(state, id); diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index 2cfe8a84e..b4a4f5d4f 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -576,35 +576,6 @@ static void write_field(lua_State *state, const struct_field_info *field, void * } } -/** - * Metamethod: represent a type node as string. - */ -static int meta_type_tostring(lua_State *state) -{ - if (!lua_getmetatable(state, 1)) - return 0; - - lua_getfield(state, -1, "__metatable"); - const char *cname = lua_tostring(state, -1); - - lua_pushstring(state, stl_sprintf("", cname).c_str()); - return 1; -} - -/** - * Metamethod: represent a DF object reference as string. - */ -static int meta_ptr_tostring(lua_State *state) -{ - uint8_t *ptr = get_object_addr(state, 1, 0, "access"); - - lua_getfield(state, UPVAL_METATABLE, "__metatable"); - const char *cname = lua_tostring(state, -1); - - lua_pushstring(state, stl_sprintf("<%s: 0x%08x>", cname, (unsigned)ptr).c_str()); - return 1; -} - /** * Metamethod: __index for structures. */ diff --git a/library/RemoteTools.cpp b/library/RemoteTools.cpp index c8af46cbf..5e11e0621 100644 --- a/library/RemoteTools.cpp +++ b/library/RemoteTools.cpp @@ -216,6 +216,9 @@ void DFHack::describeMaterial(BasicMaterialInfo *info, const MaterialInfo &mat, case MaterialInfo::Plant: info->set_plant_id(mat.index); break; + + default: + break; } } @@ -298,7 +301,7 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit, if (mask && mask->labors()) { - for (int i = 0; i < sizeof(unit->status.labors)/sizeof(bool); i++) + for (size_t i = 0; i < sizeof(unit->status.labors)/sizeof(bool); i++) if (unit->status.labors[i]) info->add_labors(i); } @@ -630,7 +633,7 @@ static command_result ListSquads(color_ostream &stream, static command_result SetUnitLabors(color_ostream &stream, const SetUnitLaborsIn *in) { - for (size_t i = 0; i < in->change_size(); i++) + for (int i = 0; i < in->change_size(); i++) { auto change = in->change(i); auto unit = df::unit::find(change.unit_id()); diff --git a/library/TileTypes.cpp b/library/TileTypes.cpp index fa5d99555..5564e5e3f 100644 --- a/library/TileTypes.cpp +++ b/library/TileTypes.cpp @@ -68,6 +68,8 @@ namespace DFHack return tiletype::LavaPillar; case tiletype_material::STONE: return tiletype::StonePillar; + default: + break; } } diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h index 02f988248..a411ae667 100644 --- a/library/include/DataDefs.h +++ b/library/include/DataDefs.h @@ -372,14 +372,14 @@ namespace DFHack template int linear_index(const DFHack::enum_list_attr &lst, T val) { - for (int i = 0; i < lst.size; i++) + for (size_t i = 0; i < lst.size; i++) if (lst.items[i] == val) return i; return -1; } inline int linear_index(const DFHack::enum_list_attr &lst, const std::string &val) { - for (int i = 0; i < lst.size; i++) + for (size_t i = 0; i < lst.size; i++) if (lst.items[i] == val) return i; return -1; diff --git a/library/include/RemoteTools.h b/library/include/RemoteTools.h index bccbb5e62..65884badc 100644 --- a/library/include/RemoteTools.h +++ b/library/include/RemoteTools.h @@ -73,7 +73,7 @@ namespace DFHack */ template void flagarray_to_ints(RepeatedField *pf, const BitArray &val) { - for (int i = 0; i < val.size*8; i++) + for (size_t i = 0; i < val.size*8; i++) if (val.is_set(T(i))) pf->Add(i); } diff --git a/library/include/modules/Windows.h b/library/include/modules/Windows.h index 314b6e292..7dbc9f1ad 100644 --- a/library/include/modules/Windows.h +++ b/library/include/modules/Windows.h @@ -117,11 +117,11 @@ namespace Windows for ( auto iter = str.begin(); iter != str.end(); iter++) { auto elem = *iter; - if(cursor_y >= height) + if(cursor_y >= (int)height) break; if(wrap) { - if(cursor_x >= width) + if(cursor_x >= (int)width) cursor_x = wrap_column; } df_screentile & tile = buffer[cursor_x * height + cursor_y]; @@ -224,12 +224,12 @@ namespace Windows virtual void blit_to_parent () { df_tilebuf par = parent->getBuffer(); - for(int xi = 0; xi < width; xi++) + for(unsigned xi = 0; xi < width; xi++) { - for(int yi = 0; yi < height; yi++) + for(unsigned yi = 0; yi < height; yi++) { - int parx = left + xi; - int pary = top + yi; + unsigned parx = left + xi; + unsigned pary = top + yi; if(pary >= par.height) continue; if(parx >= par.width) continue; par.data[parx * par.height + pary] = buffer[xi * height + yi]; diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index 8dc81911c..4c2bf8ec1 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -52,14 +52,14 @@ uint32_t Constructions::getCount() df::construction * Constructions::getConstruction(const int32_t index) { - if (index < 0 || index >= getCount()) + if (uint32_t(index) >= getCount()) return NULL; return world->constructions[index]; } bool Constructions::copyConstruction(const int32_t index, t_construction &out) { - if (index < 0 || index >= getCount()) + if (uint32_t(index) >= getCount()) return false; out.origin = world->constructions[index]; diff --git a/library/modules/Engravings.cpp b/library/modules/Engravings.cpp index 3621bc736..bff17ef5f 100644 --- a/library/modules/Engravings.cpp +++ b/library/modules/Engravings.cpp @@ -53,14 +53,14 @@ uint32_t Engravings::getCount() df::engraving * Engravings::getEngraving(int index) { - if (index < 0 || index >= getCount()) + if (uint32_t(index) >= getCount()) return NULL; return world->engravings[index]; } bool Engravings::copyEngraving(const int32_t index, t_engraving &out) { - if (index < 0 || index >= getCount()) + if (uint32_t(index) >= getCount()) return false; out.origin = world->engravings[index]; diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 592f27c0b..2eaa4c27e 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -223,7 +223,7 @@ df::job *Gui::getSelectedWorkshopJob(color_ostream &out, bool quiet) df::building *selected = world->selected_building; int idx = *ui_workshop_job_cursor; - if (idx < 0 || idx >= selected->jobs.size()) + if (size_t(idx) >= selected->jobs.size()) { out.printerr("Invalid job cursor index: %d\n", idx); return NULL; diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 9d0657e19..96fcc19ce 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -536,6 +536,9 @@ df::coord Items::getPosition(df::item *item) if (auto bld = ref->getBuilding()) return df::coord(bld->centerx, bld->centery, bld->z); break; + + default: + break; } } } diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index e130915d6..3c4933fb7 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -676,6 +676,11 @@ t_matpair MapExtras::BlockInfo::getBaseMaterial(df::tiletype tt, df::coord2d pos int x = pos.x, y = pos.y; switch (tileMaterial(tt)) { + case NONE: + case AIR: + rv.mat_type = -1; + break; + case DRIFTWOOD: case SOIL: { @@ -759,6 +764,9 @@ t_matpair MapExtras::BlockInfo::getBaseMaterial(df::tiletype tt, df::coord2d pos } case CONSTRUCTION: // just a fallback + case MAGMA: + case HFS: + // use generic 'rock' break; case FROZEN_LIQUID: @@ -776,9 +784,6 @@ t_matpair MapExtras::BlockInfo::getBaseMaterial(df::tiletype tt, df::coord2d pos case CAMPFIRE: rv.mat_type = builtin_mats::ASH; break; - - default: - rv.mat_type = -1; } return rv; @@ -1031,9 +1036,9 @@ MapExtras::Block *MapExtras::MapCache::BlockAt(DFCoord blockcoord) } else { - if(blockcoord.x >= 0 && blockcoord.x < x_bmax && - blockcoord.y >= 0 && blockcoord.y < y_bmax && - blockcoord.z >= 0 && blockcoord.z < z_max) + if(unsigned(blockcoord.x) < x_bmax && + unsigned(blockcoord.y) < y_bmax && + unsigned(blockcoord.z) < z_max) { Block * nblo = new Block(this, blockcoord); blocks[blockcoord] = nblo; diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 0172e24f8..f49dd82e2 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -80,7 +80,7 @@ bool MaterialInfo::decode(df::item *item) bool MaterialInfo::decode(const df::material_vec_ref &vr, int idx) { - if (idx < 0 || idx >= vr.mat_type.size() || idx >= vr.mat_index.size()) + if (size_t(idx) >= vr.mat_type.size() || size_t(idx) >= vr.mat_index.size()) return decode(-1); else return decode(vr.mat_type[idx], vr.mat_index[idx]); @@ -103,7 +103,7 @@ bool MaterialInfo::decode(int16_t type, int32_t index) df::world_raws &raws = world->raws; - if (type >= sizeof(raws.mat_table.builtin)/sizeof(void*)) + if (size_t(type) >= sizeof(raws.mat_table.builtin)/sizeof(void*)) return false; if (index < 0) @@ -127,7 +127,7 @@ bool MaterialInfo::decode(int16_t type, int32_t index) mode = Creature; subtype = type-CREATURE_BASE; creature = df::creature_raw::find(index); - if (!creature || subtype >= creature->material.size()) + if (!creature || size_t(subtype) >= creature->material.size()) return false; material = creature->material[subtype]; } @@ -139,7 +139,7 @@ bool MaterialInfo::decode(int16_t type, int32_t index) if (!figure) return false; creature = df::creature_raw::find(figure->race); - if (!creature || subtype >= creature->material.size()) + if (!creature || size_t(subtype) >= creature->material.size()) return false; material = creature->material[subtype]; } @@ -148,7 +148,7 @@ bool MaterialInfo::decode(int16_t type, int32_t index) mode = Plant; subtype = type-PLANT_BASE; plant = df::plant_raw::find(index); - if (!plant || subtype >= plant->material.size()) + if (!plant || size_t(subtype) >= plant->material.size()) return false; material = plant->material[subtype]; } diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 8b44d4cf9..55bd98dec 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -78,7 +78,7 @@ df::unit * Units::GetCreature (const int32_t index) if (!isValid()) return NULL; // read pointer from vector at position - if(index > world->units.all.size()) + if(size_t(index) > world->units.all.size()) return 0; return world->units.all[index]; } diff --git a/library/modules/Vegetation.cpp b/library/modules/Vegetation.cpp index bd0eeb656..a76c3a2cd 100644 --- a/library/modules/Vegetation.cpp +++ b/library/modules/Vegetation.cpp @@ -54,14 +54,14 @@ uint32_t Vegetation::getCount() df::plant * Vegetation::getPlant(const int32_t index) { - if (index < 0 || index >= getCount()) + if (uint32_t(index) >= getCount()) return NULL; return world->plants.all[index]; } bool Vegetation::copyPlant(const int32_t index, t_plant &out) { - if (index < 0 || index >= getCount()) + if (uint32_t(index) >= getCount()) return false; out.origin = world->plants.all[index]; diff --git a/library/modules/Windows.cpp b/library/modules/Windows.cpp index 0cdd7e831..e069d964e 100644 --- a/library/modules/Windows.cpp +++ b/library/modules/Windows.cpp @@ -41,7 +41,7 @@ Windows::df_screentile *Windows::getScreenBuffer() } Windows::df_window::df_window(int x, int y, unsigned int width, unsigned int height) -:buffer(0), parent(0), left(x), top(y), width(width), height(height), current_painter(NULL) +:buffer(0), width(width), height(height), parent(0), left(x), top(y), current_painter(NULL) { buffer = 0; }; diff --git a/library/xml b/library/xml index 25c2a3dad..521aad437 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 25c2a3dad964abbcceb5abd41558b71fb113e83b +Subproject commit 521aad43799ff65d772e5314972b8bc675500fb3 diff --git a/plugins/burrows.cpp b/plugins/burrows.cpp index a629e30c1..8080710c3 100644 --- a/plugins/burrows.cpp +++ b/plugins/burrows.cpp @@ -604,7 +604,7 @@ static command_result burrow(color_ostream &out, vector ¶meters) bool state = (cmd == "enable"); - for (int i = 1; i < parameters.size(); i++) + for (size_t i = 1; i < parameters.size(); i++) { string &option = parameters[i]; @@ -619,7 +619,7 @@ static command_result burrow(color_ostream &out, vector ¶meters) if (parameters.size() < 2) return CR_WRONG_USAGE; - for (int i = 1; i < parameters.size(); i++) + for (size_t i = 1; i < parameters.size(); i++) { auto target = findByName(out, parameters[i]); if (!target) @@ -642,7 +642,7 @@ static command_result burrow(color_ostream &out, vector ¶meters) bool enable = (cmd != "remove-units"); - for (int i = 2; i < parameters.size(); i++) + for (size_t i = 2; i < parameters.size(); i++) { auto source = findByName(out, parameters[i]); if (!source) @@ -656,7 +656,7 @@ static command_result burrow(color_ostream &out, vector ¶meters) if (parameters.size() < 2) return CR_WRONG_USAGE; - for (int i = 1; i < parameters.size(); i++) + for (size_t i = 1; i < parameters.size(); i++) { auto target = findByName(out, parameters[i]); if (!target) @@ -679,7 +679,7 @@ static command_result burrow(color_ostream &out, vector ¶meters) bool enable = (cmd != "remove-tiles"); - for (int i = 2; i < parameters.size(); i++) + for (size_t i = 2; i < parameters.size(); i++) { if (setTilesByKeyword(target, parameters[i], enable)) continue; diff --git a/plugins/jobutils.cpp b/plugins/jobutils.cpp index 511095943..de7f81366 100644 --- a/plugins/jobutils.cpp +++ b/plugins/jobutils.cpp @@ -193,7 +193,7 @@ static bool build_choice_matches(df::ui_build_item_req *req, df::build_req_choic { if (gen->mat_type == new_mat.type && gen->mat_index == new_mat.index && - (ignore_select || gen->used_count < gen->candidates.size())) + (ignore_select || size_t(gen->used_count) < gen->candidates.size())) { return true; } @@ -305,7 +305,7 @@ static df::job_item *getJobItem(color_ostream &out, df::job *job, std::string id return NULL; int v = atoi(idx.c_str()); - if (v < 1 || v > job->job_items.size()) { + if (v < 1 || size_t(v) > job->job_items.size()) { out.printerr("Invalid item index.\n"); return NULL; } diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp index fa1736ed7..625f4a74d 100644 --- a/plugins/mapexport/mapexport.cpp +++ b/plugins/mapexport/mapexport.cpp @@ -2,7 +2,7 @@ #include "Console.h" #include "Export.h" #include "PluginManager.h" -#include "modules/MapCache.h"f +#include "modules/MapCache.h" using namespace DFHack; #include @@ -50,6 +50,7 @@ static dfproto::Tile::TileMaterialType toProto(df::tiletype_material mat) switch (mat) { #define CONVERT(name) case tiletype_material::name: return dfproto::Tile::name; + case tiletype_material::NONE: CONVERT(AIR) case tiletype_material::PLANT: CONVERT(SOIL) @@ -74,9 +75,8 @@ static dfproto::Tile::TileMaterialType toProto(df::tiletype_material mat) CONVERT(BROOK) CONVERT(RIVER) #undef CONVERT - default: - return dfproto::Tile::AIR; } + return dfproto::Tile::AIR; } command_result mapexport (color_ostream &out, std::vector & parameters) diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index aa3c94a55..5e5ca84bc 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -892,6 +892,9 @@ static void guess_job_material(df::job *job, MaterialInfo &mat, df::dfhack_mater case item_type::WOOD: mat_mask.bits.wood = mat_mask.bits.wood2 = true; break; + + default: + break; } } } @@ -1148,6 +1151,9 @@ static void map_job_items(color_ostream &out) if (item->getTotalDimension() < 10000) is_invalid = true; break; + + default: + break; } if (item->flags.bits.melt && !item->flags.bits.owned && !itemBusy(item))