From 61dea59e2927996a4bd4c9dae682c3184e56f842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 15 May 2011 22:24:40 +0200 Subject: [PATCH] Fix a big heap of warnings. --- library/DFProcess-linux-base.cpp | 2 +- library/DFProcess_C.cpp | 151 +++++++++++++---------------- library/DFTileTypes.cpp | 7 +- library/VersionInfo.cpp | 6 +- library/include/dfhack/DFProcess.h | 2 +- library/include/dfhack/DFVector.h | 2 + library/modules/Gui.cpp | 1 + library/modules/Items.cpp | 3 +- library/modules/Maps.cpp | 2 +- library/modules/Materials.cpp | 16 +-- tools/examples/spatterdump.cpp | 1 + 11 files changed, 92 insertions(+), 101 deletions(-) diff --git a/library/DFProcess-linux-base.cpp b/library/DFProcess-linux-base.cpp index 92628dd1d..ed4da316a 100644 --- a/library/DFProcess-linux-base.cpp +++ b/library/DFProcess-linux-base.cpp @@ -106,7 +106,7 @@ bool LinuxProcessBase::getThreadIDs(vector & threads ) return false; } threads.clear(); - for(int i = 0; i < subdirs.size();i++) + for(size_t i = 0; i < subdirs.size();i++) { uint32_t tid; if(sscanf(subdirs[i].c_str(),"%d", &tid)) diff --git a/library/DFProcess_C.cpp b/library/DFProcess_C.cpp index b660a2706..ed9bcc285 100644 --- a/library/DFProcess_C.cpp +++ b/library/DFProcess_C.cpp @@ -223,97 +223,82 @@ const char* Process_readClassName(DFHackObject* p_Ptr, uint32_t vptr) uint32_t* Process_getThreadIDs(DFHackObject* p_Ptr) { - if(p_Ptr == NULL || alloc_uint_buffer_callback == NULL) - return NULL; - - std::vector threads; - - if(((DFHack::Process*)p_Ptr)->getThreadIDs(threads)) - { - uint32_t* buf; - - if(threads.size() > 0) - { - ((*alloc_uint_buffer_callback)(&buf, threads.size())); - - if(buf == NULL) - return NULL; - - copy(threads.begin(), threads.end(), buf); - - return buf; - } - } - else - return NULL; + if(p_Ptr == NULL || alloc_uint_buffer_callback == NULL) + return NULL; + + std::vector threads; + + if(((DFHack::Process*)p_Ptr)->getThreadIDs(threads)) + { + uint32_t* buf; + if(threads.size() > 0) + { + ((*alloc_uint_buffer_callback)(&buf, threads.size())); + if(buf == NULL) + return NULL; + copy(threads.begin(), threads.end(), buf); + return buf; + } + } + return NULL; } t_memrange* Process_getMemRanges(DFHackObject* p_Ptr) { - if(p_Ptr == NULL || alloc_memrange_buffer_callback == NULL) - return NULL; - - std::vector ranges; - - ((DFHack::Process*)p_Ptr)->getMemRanges(ranges); - - if(ranges.size() > 0) - { - t_memrange* buf; - uint32_t* rangeDescriptorBuf = (uint32_t*)calloc(ranges.size(), sizeof(uint32_t)); - - for(uint32_t i = 0; i < ranges.size(); i++) - { - t_memrange* r = &ranges[i]; - - rangeDescriptorBuf[i] = (uint32_t)(r->end - r->start); - } - - ((*alloc_memrange_buffer_callback)(&buf, rangeDescriptorBuf, ranges.size())); - - free(rangeDescriptorBuf); - - if(buf == NULL) - return NULL; - - for(uint32_t i = 0; i < ranges.size(); i++) - { - t_memrange* r = &ranges[i]; - - buf[i].start = r->start; - buf[i].end = r->end; - - memset(buf[i].name, '\0', 1024); - strncpy(buf[i].name, r->name, 1024); - - buf[i].read = r->read; - buf[i].write = r->write; - buf[i].execute = r->execute; - buf[i].shared = r->shared; - buf[i].valid = r->valid; - - memcpy(buf[i].buffer, r->buffer, r->end - r->start); - } - - return buf; - } - else - return NULL; + if(p_Ptr == NULL || alloc_memrange_buffer_callback == NULL) + return NULL; + + std::vector ranges; + + ((DFHack::Process*)p_Ptr)->getMemRanges(ranges); + + if(ranges.size() > 0) + { + t_memrange* buf; + uint32_t* rangeDescriptorBuf = (uint32_t*)calloc(ranges.size(), sizeof(uint32_t)); + + for(uint32_t i = 0; i < ranges.size(); i++) + { + t_memrange* r = &ranges[i]; + rangeDescriptorBuf[i] = (uint32_t)(r->end - r->start); + } + + ((*alloc_memrange_buffer_callback)(&buf, rangeDescriptorBuf, ranges.size())); + free(rangeDescriptorBuf); + if(buf == NULL) + return NULL; + + for(uint32_t i = 0; i < ranges.size(); i++) + { + t_memrange* r = &ranges[i]; + buf[i].start = r->start; + buf[i].end = r->end; + memset(buf[i].name, '\0', 1024); + strncpy(buf[i].name, r->name, 1024); + buf[i].read = r->read; + buf[i].write = r->write; + buf[i].execute = r->execute; + buf[i].shared = r->shared; + buf[i].valid = r->valid; + memcpy(buf[i].buffer, r->buffer, r->end - r->start); + } + return buf; + } + return NULL; } int Process_getPID(DFHackObject* p_Ptr, int32_t* pid) { - if(p_Ptr == NULL) - { - *pid = -1; - return -1; - } - else - { - *pid = ((DFHack::Process*)p_Ptr)->getPID(); - - return 1; - } + if(p_Ptr == NULL) + { + *pid = -1; + return -1; + } + else + { + *pid = ((DFHack::Process*)p_Ptr)->getPID(); + return 1; + } } int Process_getModuleIndex(DFHackObject* p_Ptr, char* name, uint32_t version, uint32_t* output) diff --git a/library/DFTileTypes.cpp b/library/DFTileTypes.cpp index b22748ab2..a2343433d 100644 --- a/library/DFTileTypes.cpp +++ b/library/DFTileTypes.cpp @@ -658,7 +658,7 @@ namespace DFHack int32_t findSimilarTileType( const int32_t sourceTileType, const TileShape tshape ) { - int32_t tt, maybe=0, match=0; + int32_t tt, match=0; int value=0, matchv=0; const TileRow *source = &tileTypeTable[sourceTileType]; @@ -676,7 +676,7 @@ namespace DFHack //Special flag match is absolutely mandatory! if( source->special != tileTypeTable[tt].special ) continue; - maybe=tt; value=0; + value=0; //Material is high-value match if( tileTypeTable[tt].material == source->material ) value|=8; //Direction is medium value match @@ -685,7 +685,8 @@ namespace DFHack if( tileTypeTable[tt].variant == source->variant ) value|=1; //Check value against last match - if( value>matchv ){ + if( value>matchv ) + { match=tt; matchv=value; } diff --git a/library/VersionInfo.cpp b/library/VersionInfo.cpp index 720121f63..7e6f52abc 100644 --- a/library/VersionInfo.cpp +++ b/library/VersionInfo.cpp @@ -229,7 +229,7 @@ void OffsetGroup::setAddress (const string & key, const string & value, const IN uint32_Iter it = OGd->addresses.find(key); if(it != OGd->addresses.end()) { - int32_t address = strtol(value.c_str(), NULL, 16); + uint32_t address = strtol(value.c_str(), NULL, 16); if((*it).second.second == address) std::cout << "Pointless address setting: " << this->getFullName() + key << endl; (*it).second.second = address; @@ -484,7 +484,7 @@ std::string OffsetGroup::PrintOffsets(int indentation) } } std::sort(addrsorter.begin(), addrsorter.end(), compare_pair_first<>()); - for(int idx = 0; idx < addrsorter.size();idx++) + for(size_t idx = 0; idx < addrsorter.size();idx++) { horrible & h = addrsorter[idx]; ss << i << "
()); - for(int idx = 0; idx < offsorter.size();idx++) + for(size_t idx = 0; idx < offsorter.size();idx++) { terrible & h = offsorter[idx]; ss << i << "::iterator it = classNameCache.find(vptr); if (it != classNameCache.end()) return it->second; diff --git a/library/include/dfhack/DFVector.h b/library/include/dfhack/DFVector.h index b9e4d698e..a688919ea 100644 --- a/library/include/dfhack/DFVector.h +++ b/library/include/dfhack/DFVector.h @@ -43,6 +43,7 @@ namespace DFHack Process *_p; uint32_t _address; t_vecTriplet t; + t_vecTriplet t_read; uint32_t _size;// vector size T * data; // cached data @@ -57,6 +58,7 @@ namespace DFHack DfVector(Process *p, uint32_t address) : _p(p), _address(address) { p->readSTLVector(address,t); + t_read = t; uint32_t byte_size = t.end - t.start; _size = byte_size / sizeof(T); data = new T[_size]; diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index acfce4a91..b0fdf2b59 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -148,6 +148,7 @@ uint32_t Gui::ReadMenuState() return false; } +// FIXME: variable ‘screenAddr’ set but not used [-Wunused-but-set-variable] bool Gui::ReadViewScreen (t_viewscreen &screen) { if (!d->ViewScreeInited) return false; diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index e9affec1a..b9529c840 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -353,7 +353,6 @@ Accessor * buildAccessor (OffsetGroup * I, Process * p, const char * name, uint3 ItemDesc::ItemDesc(uint32_t VTable, Process *p) { - int32_t funcOffsetA, funcOffsetB, funcOffsetC, funcOffsetD, funcOffsetQuality, funcOffsetWear; OffsetGroup * Items = p->getDescriptor()->getGroup("Items"); /* @@ -381,7 +380,7 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p) mainType = this->AMainType->getValue(0); else { - fprintf(stderr, "Bad item main type at function %p\n", (void*) p->readDWord( VTable + funcOffsetA )); + cerr << "Bad item main type accessor: " << AMainType->dump() << endl; mainType = 0; } } diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index f17a1a41d..76e9f5e6c 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -802,7 +802,7 @@ bool Maps::StartFeatures() t_feature * Maps::GetGlobalFeature(int16_t index) { if(!d->FeaturesStarted) return 0; - if(index < 0 || index >= d->v_global_feature.size()) + if(index < 0 || uint16_t(index) >= d->v_global_feature.size()) return 0; return &(d->v_global_feature[index]); } diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index eae1ee345..f8e0399cc 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -356,9 +356,10 @@ bool Materials::ReadCreatureTypesEx (void) uint32_t caste_bodypart_offset; uint32_t bodypart_id_offset; uint32_t bodypart_category_offset; - uint32_t bodypart_layers_offset; - uint32_t bodypart_singular_offset; - uint32_t bodypart_plural_offset; + //FIXME: this is unused. why do we mess with it when it's not even read? + //uint32_t bodypart_layers_offset; + //uint32_t bodypart_singular_offset; + //uint32_t bodypart_plural_offset; uint32_t color_modifier_part_offset; uint32_t color_modifier_startdate_offset; uint32_t color_modifier_enddate_offset; @@ -371,9 +372,9 @@ bool Materials::ReadCreatureTypesEx (void) OffsetGroup * OG_CasteBodyparts = OG_Creature->getGroup("caste_bodyparts"); bodypart_id_offset = OG_CasteBodyparts->getOffset ("id"); bodypart_category_offset = OG_CasteBodyparts->getOffset ("category"); - bodypart_layers_offset = OG_CasteBodyparts->getOffset ("layers_vector"); // unused - bodypart_singular_offset = OG_CasteBodyparts->getOffset ("singular_vector"); // unused - bodypart_plural_offset = OG_CasteBodyparts->getOffset ("plural_vector"); // unused + //bodypart_layers_offset = OG_CasteBodyparts->getOffset ("layers_vector"); // unused + //bodypart_singular_offset = OG_CasteBodyparts->getOffset ("singular_vector"); // unused + //bodypart_plural_offset = OG_CasteBodyparts->getOffset ("plural_vector"); // unused OffsetGroup * OG_CasteColorMods = OG_Creature->getGroup("caste_color_mods"); color_modifier_part_offset = OG_CasteColorMods->getOffset ("part"); color_modifier_startdate_offset = OG_CasteColorMods->getOffset ("startdate"); @@ -480,11 +481,11 @@ void Materials::ReadAllMaterials(void) } /// miserable pile of magic. The material system is insane. +// FIXME: this contains potential errors when the indexes are -1 and compared to unsigned numbers! std::string Materials::getDescription(const t_material & mat) { std::string out; int32_t typeC; - if ( (mat.subIndex<419) || (mat.subIndex>618) ) { if ( (mat.subIndex<19) || (mat.subIndex>218) ) @@ -543,6 +544,7 @@ std::string Materials::getDescription(const t_material & mat) } //type of material only so we know which vector to retrieve +// FIXME: this also contains potential errors when the indexes are -1 and compared to unsigned numbers! std::string Materials::getType(const t_material & mat) { if((mat.subIndex<419) || (mat.subIndex>618)) diff --git a/tools/examples/spatterdump.cpp b/tools/examples/spatterdump.cpp index 4fbed7157..20c0acf13 100644 --- a/tools/examples/spatterdump.cpp +++ b/tools/examples/spatterdump.cpp @@ -13,6 +13,7 @@ using namespace std; using namespace DFHack; +//FIXME: A pile of magic numbers. looks like decompiled number typedef uint32_t _DWORD; int get_material_vector(uint32_t vein_8, uint16_t vein_4, int WORLD_) {