mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Fix memory corruption during loading artifacts from mods
This commit is contained in:
		| @@ -439,13 +439,13 @@ void CArtHandler::loadGrowingArt(CGrowingArtifact * art, const JsonNode & node) | ||||
| { | ||||
| 	for (auto b : node["growing"]["bonusesPerLevel"].Vector()) | ||||
| 	{ | ||||
| 		auto bonus = JsonUtils::parseBonus (b["bonus"]); | ||||
| 		art->bonusesPerLevel.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *bonus)); | ||||
| 		art->bonusesPerLevel.push_back(std::pair <ui16, Bonus>(b["level"].Float(), Bonus())); | ||||
| 		JsonUtils::parseBonus(b["bonus"], &art->bonusesPerLevel.back().second); | ||||
| 	} | ||||
| 	for (auto b : node["growing"]["thresholdBonuses"].Vector()) | ||||
| 	{ | ||||
| 		auto bonus = JsonUtils::parseBonus (b["bonus"]); | ||||
| 		art->thresholdBonuses.push_back (std::pair <ui16, Bonus> (b["level"].Float(), *bonus)); | ||||
| 		art->thresholdBonuses.push_back(std::pair <ui16, Bonus>(b["level"].Float(), Bonus())); | ||||
| 		JsonUtils::parseBonus(b["bonus"], &art->thresholdBonuses.back().second); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -54,8 +54,10 @@ void CIdentifierStorage::checkIdentifier(std::string & ID) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| CIdentifierStorage::ObjectCallback::ObjectCallback(std::string localScope, std::string remoteScope, std::string type, | ||||
| 												   std::string name, const std::function<void(si32)> & callback, bool optional): | ||||
| CIdentifierStorage::ObjectCallback::ObjectCallback( | ||||
| 		std::string localScope, std::string remoteScope, std::string type, | ||||
| 		std::string name, const std::function<void(si32)> & callback, | ||||
| 		bool optional): | ||||
| 	localScope(localScope), | ||||
| 	remoteScope(remoteScope), | ||||
| 	type(type), | ||||
|   | ||||
| @@ -41,7 +41,10 @@ class CIdentifierStorage | ||||
| 		std::function<void(si32)> callback; | ||||
| 		bool optional; | ||||
|  | ||||
| 		ObjectCallback(std::string localScope, std::string remoteScope, std::string type, std::string name, const std::function<void(si32)> & callback, bool optional); | ||||
| 		ObjectCallback(std::string localScope, std::string remoteScope, | ||||
| 		               std::string type, std::string name, | ||||
| 		               const std::function<void(si32)> & callback, | ||||
| 		               bool optional); | ||||
| 	}; | ||||
|  | ||||
| 	struct ObjectData // entry created on ID registration | ||||
|   | ||||
| @@ -1110,10 +1110,6 @@ Bonus::Bonus() | ||||
| 	sid = 0; | ||||
| } | ||||
|  | ||||
| Bonus::~Bonus() | ||||
| { | ||||
| } | ||||
|  | ||||
| std::shared_ptr<Bonus> Bonus::addPropagator(TPropagatorPtr Propagator) | ||||
| { | ||||
| 	propagator = Propagator; | ||||
|   | ||||
| @@ -313,7 +313,6 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus> | ||||
| 	Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1); | ||||
| 	Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype=-1, ValueType ValType = ADDITIVE_VALUE); | ||||
| 	Bonus(); | ||||
| 	~Bonus(); | ||||
|  | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
|   | ||||
| @@ -420,8 +420,16 @@ void JsonUtils::resolveIdentifier (const JsonNode &node, si32 &var) | ||||
|  | ||||
| std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonNode &ability) | ||||
| { | ||||
|  | ||||
| 	auto b = std::make_shared<Bonus>(); | ||||
| 	if (!parseBonus(ability, b.get())) | ||||
| 	{ | ||||
| 		return nullptr; | ||||
| 	} | ||||
| 	return b; | ||||
| } | ||||
|  | ||||
| bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b) | ||||
| { | ||||
| 	const JsonNode *value; | ||||
|  | ||||
| 	std::string type = ability["type"].String(); | ||||
| @@ -429,7 +437,7 @@ std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonNode &ability) | ||||
| 	if (it == bonusNameMap.end()) | ||||
| 	{ | ||||
| 		logGlobal->errorStream() << "Error: invalid ability type " << type; | ||||
| 		return b; | ||||
| 		return false; | ||||
| 	} | ||||
| 	b->type = it->second; | ||||
|  | ||||
| @@ -542,7 +550,7 @@ std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonNode &ability) | ||||
| 	if (!value->isNull()) | ||||
| 		b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type "); | ||||
|  | ||||
| 	return b; | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| //returns first Key with value equal to given one | ||||
|   | ||||
| @@ -131,7 +131,8 @@ namespace JsonUtils | ||||
|  | ||||
| 	/// | ||||
| 	DLL_LINKAGE std::shared_ptr<Bonus> parseBonus(const JsonVector &ability_vec); | ||||
| 	DLL_LINKAGE std::shared_ptr<Bonus> parseBonus (const JsonNode &bonus); | ||||
| 	DLL_LINKAGE std::shared_ptr<Bonus> parseBonus(const JsonNode &ability); | ||||
| 	DLL_LINKAGE bool parseBonus(const JsonNode &ability, Bonus *placement); | ||||
| 	DLL_LINKAGE void unparseBonus (JsonNode &node, const std::shared_ptr<Bonus>& bonus); | ||||
| 	DLL_LINKAGE void resolveIdentifier(si32 &var, const JsonNode &node, std::string name); | ||||
| 	DLL_LINKAGE void resolveIdentifier(const JsonNode &node, si32 &var); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user