From 2682c54fced9494246da8ae259715e39529473a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 1 Mar 2012 01:29:55 +0100 Subject: [PATCH] Fix horrible errors and make MSVC shut upt about non-issues. --- library/Core.cpp | 27 +++++---------------------- library/VersionInfoFactory.cpp | 2 -- library/include/BitArray.h | 11 +++++++++-- library/include/Pragma.h | 3 +++ library/modules/Gui.cpp | 10 +++++----- library/modules/Materials.cpp | 26 +++++++++++++------------- 6 files changed, 35 insertions(+), 44 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index c489432f7..aa3a8702d 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -104,7 +104,7 @@ void cheap_tokenise(string const& input, vector &output) string *cur = NULL; for (size_t i = 0; i < input.size(); i++) { - char c = input[i]; + unsigned char c = input[i]; if (isspace(c)) { cur = NULL; } else { @@ -470,28 +470,11 @@ static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clue } else { - vector parts; - cheap_tokenise(command,parts); - if(parts.size() == 0) + command_result res = plug_mgr->InvokeCommand(first, parts); + if(res == CR_NOT_IMPLEMENTED) { - clueless_counter++; - } - else - { - string first = parts[0]; - parts.erase(parts.begin()); - command_result res = plug_mgr->InvokeCommand(first, parts); - if(res == CR_NOT_IMPLEMENTED) - { - con.printerr("%s is not a recognized command.\n", first.c_str()); - clueless_counter ++; - } - /* - else if(res == CR_FAILURE) - { - con.printerr("ERROR!\n"); - } - */ + con.printerr("%s is not a recognized command.\n", first.c_str()); + clueless_counter ++; } } } diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index 7d963673b..66cea00a9 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -60,7 +60,6 @@ void VersionInfoFactory::clear() VersionInfo * VersionInfoFactory::getVersionInfoByMD5(string hash) { - VersionInfo * vinfo; for(size_t i = 0; i < versions.size();i++) { if(versions[i]->hasMD5(hash)) @@ -167,7 +166,6 @@ bool VersionInfoFactory::loadFile(string path_to_xml) TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); - VersionInfo *mem; // block: name { diff --git a/library/include/BitArray.h b/library/include/BitArray.h index b3ca6d7c1..6759b9247 100644 --- a/library/include/BitArray.h +++ b/library/include/BitArray.h @@ -29,6 +29,7 @@ distribution. #include #include #include +#include //#include namespace DFHack { @@ -62,7 +63,10 @@ namespace DFHack { if (newsize == size) return; - bits = (uint8_t*)realloc(bits, newsize); + uint8_t* mem = (uint8_t *) realloc(bits, newsize); + if(!mem) + throw std::bad_alloc(); + bits = mem; if (newsize > size) memset(bits+size, 0, newsize-size); size = newsize; @@ -197,7 +201,10 @@ namespace DFHack } else { - m_data = (T*)realloc(m_data, sizeof(T)*new_size); + T* mem = (T*) realloc(m_data, sizeof(T)*new_size); + if(!mem) + throw std::bad_alloc(); + m_data = mem; } if (new_size > m_size) memset(m_data+sizeof(T)*m_size, 0, sizeof(T)*(new_size - m_size)); diff --git a/library/include/Pragma.h b/library/include/Pragma.h index 156ff2db5..d2ca47c01 100644 --- a/library/include/Pragma.h +++ b/library/include/Pragma.h @@ -51,6 +51,9 @@ distribution. #pragma warning( disable: 4068 ) // no signed value outside enum range bs #pragma warning( disable: 4341) + // just shut up already. + #pragma warning( disable: 4244) + #pragma warning( disable: 4018) #endif #endif diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index af41a57f1..115508995 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -241,19 +241,19 @@ df::job *DFHack::getSelectedJob(Core *c, bool quiet) { df::viewscreen *top = c->getTopViewscreen(); - if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top)) + if (VIRTUAL_CAST_VAR(joblist, df::viewscreen_joblistst, top)) { - df::job *job = vector_get(screen->jobs, screen->cursor_pos); + df::job *job = vector_get(joblist->jobs, joblist->cursor_pos); if (!job && !quiet) c->con.printerr("Selected unit has no job\n"); return job; } - else if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top)) + else if (VIRTUAL_CAST_VAR(unitlist, df::viewscreen_unitlistst, top)) { - int page = screen->page; - df::job *job = vector_get(screen->jobs[page], screen->cursor_pos[page]); + int page = unitlist->page; + df::job *job = vector_get(unitlist->jobs[page], unitlist->cursor_pos[page]); if (!job && !quiet) c->con.printerr("Selected unit has no job\n"); diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index e52ebb283..0a8261413 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -771,19 +771,19 @@ bool Materials::ReadCreatureTypesEx (void) caste.recuperation[k] = ca->attributes.phys_att_range[physical_attribute_type::RECUPERATION][k]; caste.disease_resistance[k] = ca->attributes.phys_att_range[physical_attribute_type::DISEASE_RESISTANCE][k]; - caste.analytical_ability[k] = ca->attributes.phys_att_range[mental_attribute_type::ANALYTICAL_ABILITY][k]; - caste.focus[k] = ca->attributes.phys_att_range[mental_attribute_type::FOCUS][k]; - caste.willpower[k] = ca->attributes.phys_att_range[mental_attribute_type::WILLPOWER][k]; - caste.creativity[k] = ca->attributes.phys_att_range[mental_attribute_type::CREATIVITY][k]; - caste.intuition[k] = ca->attributes.phys_att_range[mental_attribute_type::INTUITION][k]; - caste.patience[k] = ca->attributes.phys_att_range[mental_attribute_type::PATIENCE][k]; - caste.memory[k] = ca->attributes.phys_att_range[mental_attribute_type::MEMORY][k]; - caste.linguistic_ability[k] = ca->attributes.phys_att_range[mental_attribute_type::LINGUISTIC_ABILITY][k]; - caste.spatial_sense[k] = ca->attributes.phys_att_range[mental_attribute_type::SPATIAL_SENSE][k]; - caste.musicality[k] = ca->attributes.phys_att_range[mental_attribute_type::MUSICALITY][k]; - caste.kinesthetic_sense[k] = ca->attributes.phys_att_range[mental_attribute_type::KINESTHETIC_SENSE][k]; - caste.empathy[k] = ca->attributes.phys_att_range[mental_attribute_type::EMPATHY][k]; - caste.social_awareness[k] = ca->attributes.phys_att_range[mental_attribute_type::SOCIAL_AWARENESS][k]; + caste.analytical_ability[k] = ca->attributes.ment_att_range[mental_attribute_type::ANALYTICAL_ABILITY][k]; + caste.focus[k] = ca->attributes.ment_att_range[mental_attribute_type::FOCUS][k]; + caste.willpower[k] = ca->attributes.ment_att_range[mental_attribute_type::WILLPOWER][k]; + caste.creativity[k] = ca->attributes.ment_att_range[mental_attribute_type::CREATIVITY][k]; + caste.intuition[k] = ca->attributes.ment_att_range[mental_attribute_type::INTUITION][k]; + caste.patience[k] = ca->attributes.ment_att_range[mental_attribute_type::PATIENCE][k]; + caste.memory[k] = ca->attributes.ment_att_range[mental_attribute_type::MEMORY][k]; + caste.linguistic_ability[k] = ca->attributes.ment_att_range[mental_attribute_type::LINGUISTIC_ABILITY][k]; + caste.spatial_sense[k] = ca->attributes.ment_att_range[mental_attribute_type::SPATIAL_SENSE][k]; + caste.musicality[k] = ca->attributes.ment_att_range[mental_attribute_type::MUSICALITY][k]; + caste.kinesthetic_sense[k] = ca->attributes.ment_att_range[mental_attribute_type::KINESTHETIC_SENSE][k]; + caste.empathy[k] = ca->attributes.ment_att_range[mental_attribute_type::EMPATHY][k]; + caste.social_awareness[k] = ca->attributes.ment_att_range[mental_attribute_type::SOCIAL_AWARENESS][k]; } mat.castes.push_back(caste); }