1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Merge pull request #1859 from rilian-la-te/fix-stack-smash

vcmi: fix stack smash
This commit is contained in:
Ivan Savenko
2023-04-03 00:41:44 +03:00
committed by GitHub
2 changed files with 12 additions and 12 deletions

View File

@@ -22,20 +22,20 @@ VCMI_LIB_NAMESPACE_BEGIN
Res::ResourceSet::ResourceSet(const JsonNode & node) Res::ResourceSet::ResourceSet(const JsonNode & node)
{ {
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++)
this[i] = static_cast<int>(node[GameConstants::RESOURCE_NAMES[i]].Float()); container[i] = static_cast<int>(node[GameConstants::RESOURCE_NAMES[i]].Float());
} }
Res::ResourceSet::ResourceSet(TResource wood, TResource mercury, TResource ore, TResource sulfur, TResource crystal, Res::ResourceSet::ResourceSet(TResource wood, TResource mercury, TResource ore, TResource sulfur, TResource crystal,
TResource gems, TResource gold, TResource mithril) TResource gems, TResource gold, TResource mithril)
{ {
this[Res::WOOD] = wood; container[Res::WOOD] = wood;
this[Res::MERCURY] = mercury; container[Res::MERCURY] = mercury;
this[Res::ORE] = ore; container[Res::ORE] = ore;
this[Res::SULFUR] = sulfur; container[Res::SULFUR] = sulfur;
this[Res::CRYSTAL] = crystal; container[Res::CRYSTAL] = crystal;
this[Res::GEMS] = gems; container[Res::GEMS] = gems;
this[Res::GOLD] = gold; container[Res::GOLD] = gold;
this[Res::MITHRIL] = mithril; container[Res::MITHRIL] = mithril;
} }
void Res::ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName) void Res::ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)

View File

@@ -36,7 +36,7 @@ namespace Res
class ResourceSet class ResourceSet
{ {
private: private:
std::array<int, GameConstants::RESOURCE_QUANTITY> container; std::array<TResource, GameConstants::RESOURCE_QUANTITY> container;
public: public:
// read resources set from json. Format example: { "gold": 500, "wood":5 } // read resources set from json. Format example: { "gold": 500, "wood":5 }
DLL_LINKAGE ResourceSet(const JsonNode & node); DLL_LINKAGE ResourceSet(const JsonNode & node);
@@ -105,12 +105,12 @@ namespace Res
TResource & operator[](size_t index) TResource & operator[](size_t index)
{ {
return container[index]; return container.at(index);
} }
const TResource & operator[](size_t index) const const TResource & operator[](size_t index) const
{ {
return container[index]; return container.at(index);
} }
bool empty () const bool empty () const