Enable warnings correctly on linux and fix a lot of them.

develop
Alexander Gavrilov 2012-04-20 13:30:37 +04:00
parent d95cc3435f
commit 0a6982f404
25 changed files with 75 additions and 81 deletions

@ -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()

@ -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})

@ -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. */

@ -98,7 +98,7 @@ std::vector<compound_identity*> 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<std::string> *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)

@ -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);

@ -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("<type: %s>", 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.
*/

@ -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());

@ -68,6 +68,8 @@ namespace DFHack
return tiletype::LavaPillar;
case tiletype_material::STONE:
return tiletype::StonePillar;
default:
break;
}
}

@ -372,14 +372,14 @@ namespace DFHack
template<class T>
int linear_index(const DFHack::enum_list_attr<T> &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<const char*> &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;

@ -73,7 +73,7 @@ namespace DFHack
*/
template<class T>
void flagarray_to_ints(RepeatedField<google::protobuf::int32> *pf, const BitArray<T> &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);
}

@ -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];

@ -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];

@ -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];

@ -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;

@ -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;
}
}
}

@ -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;

@ -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];
}

@ -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];
}

@ -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];

@ -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;
};

@ -1 +1 @@
Subproject commit 25c2a3dad964abbcceb5abd41558b71fb113e83b
Subproject commit 521aad43799ff65d772e5314972b8bc675500fb3

@ -604,7 +604,7 @@ static command_result burrow(color_ostream &out, vector <string> &parameters)
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 <string> &parameters)
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 <string> &parameters)
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 <string> &parameters)
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 <string> &parameters)
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;

@ -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;
}

@ -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 <fstream>
@ -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 <std::string> & parameters)

@ -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))