From 06115c652382d81bb25ce1dc3ad40e14f00ee273 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 11 May 2009 20:05:55 +0200 Subject: Fixed the memory issues with the pointers to item stat modifiers It was a list of pointers to Stat instances that had long been popped off the stack and deleted. --- src/resources/itemdb.cpp | 10 +++++----- src/resources/itemdb.h | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/resources') diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 66c07849..99907ca7 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -55,9 +55,9 @@ static char const *const fields[][2] = { "mp", N_("MP %+d") } }; -static std::list extraStats; +static std::list extraStats; -void ItemDB::setStatsList(std::list stats) +void ItemDB::setStatsList(const std::list &stats) { extraStats = stats; } @@ -163,13 +163,13 @@ void ItemDB::load() if (!effect.empty()) effect += " / "; effect += strprintf(gettext(fields[i][1]), value); } - for (std::list::iterator it = extraStats.begin(); + for (std::list::iterator it = extraStats.begin(); it != extraStats.end(); it++) { - int value = XML::getProperty(node, (*it)->tag.c_str(), 0); + int value = XML::getProperty(node, it->tag.c_str(), 0); if (!value) continue; if (!effect.empty()) effect += " / "; - effect += strprintf((*it)->format.c_str(), value); + effect += strprintf(it->format.c_str(), value); } std::string temp = XML::getProperty(node, "effect", ""); if (!effect.empty() && !temp.empty()) diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 2bb8fd5e..d0964e49 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -46,12 +46,19 @@ namespace ItemDB const ItemInfo &get(int id); const ItemInfo &get(const std::string &name); - struct Stat { + struct Stat + { + Stat(const std::string &tag, + const std::string &format): + tag(tag), + format(format) + {} + std::string tag; std::string format; }; - void setStatsList(std::list stats); + void setStatsList(const std::list &stats); // Items database typedef std::map ItemInfos; -- cgit v1.2.3-70-g09d2