1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixed a few CWE-457

This commit is contained in:
AlexVinS 2016-11-27 22:07:01 +03:00
parent abe4beebc6
commit 3216422307
23 changed files with 93 additions and 26 deletions

View File

@ -667,11 +667,6 @@ void processCommand(const std::string &message)
{
vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
}
else if (cn == "ai")
{
VLC->IS_AI_ENABLED = !VLC->IS_AI_ENABLED;
std::cout << "Current AI status: " << (VLC->IS_AI_ENABLED ? "enabled" : "disabled") << std::endl;
}
else if(cn == "mp" && adventureInt)
{
if(const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(adventureInt->selection))

View File

@ -76,6 +76,9 @@ CArtifact::CArtifact()
possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
possibleSlots[ArtBearer::COMMANDER];
iconIndex = ArtifactID::NONE;
price = 0;
aClass = ART_SPECIAL;
}
CArtifact::~CArtifact()

View File

@ -54,6 +54,12 @@ public:
std::string large; // big image for cutom artifacts, used in drag & drop
std::string advMapDef; //used for adventure map object
si32 iconIndex;
ui32 price;
std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition> > possibleSlots; //Bearer Type => ids of slots where artifact can be placed
std::unique_ptr<std::vector<CArtifact *> > constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
std::vector<CArtifact *> constituentOf; // Reverse map of constituents - combined arts that include this art
EartClass aClass;
ArtifactID id;
const std::string &Name() const; //getter
const std::string &Description() const; //getter
@ -68,13 +74,6 @@ public:
virtual void levelUpArtifact (CArtifactInstance * art){};
ui32 price;
std::map<ArtBearer::ArtBearer, std::vector<ArtifactPosition> > possibleSlots; //Bearer Type => ids of slots where artifact can be placed
std::unique_ptr<std::vector<CArtifact *> > constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
std::vector<CArtifact *> constituentOf; // Reverse map of constituents - combined arts that include this art
EartClass aClass;
ArtifactID id;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CBonusSystemNode&>(*this);

View File

@ -105,9 +105,15 @@ si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatur
CCreature::CCreature()
{
doubleWide = false;
setNodeType(CBonusSystemNode::CREATURE);
faction = 0;
level = 0;
fightValue = AIValue = growth = hordeGrowth = ammMin = ammMax = 0;
doubleWide = false;
special = true;
iconIndex = -1;
}
void CCreature::addBonus(int val, Bonus::BonusType type, int subtype /*= -1*/)
{
auto added = std::make_shared<Bonus>(Bonus::PERMANENT, type, Bonus::CREATURE_ABILITY, val, idNumber, subtype, Bonus::BASE_NUMBER);

View File

@ -656,6 +656,7 @@ CGameState::CGameState()
//objCaller = new CObjectCallersHandler;
globalEffects.setDescription("Global effects");
globalEffects.setNodeType(CBonusSystemNode::GLOBAL_EFFECTS);
day = 0;
}
CGameState::~CGameState()
@ -2866,8 +2867,8 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
}
PlayerState::PlayerState()
: color(-1), enteredWinningCheatCode(0),
enteredLosingCheatCode(0), status(EPlayerStatus::INGAME)
: color(-1), human(false), enteredWinningCheatCode(false),
enteredLosingCheatCode(false), status(EPlayerStatus::INGAME)
{
setNodeType(PLAYER);
}

View File

@ -173,7 +173,9 @@ struct DLL_LINKAGE QuestInfo //universal interface for human and AI
const CGObjectInstance * obj; //related object, most likely Seer Hut
int3 tile;
QuestInfo(){};
QuestInfo()
: quest(nullptr), obj(nullptr), tile(-1,-1,-1)
{};
QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) :
quest (Quest), obj (Obj), tile (Tile){};

View File

@ -59,7 +59,7 @@ EAlignment::EAlignment CHeroClass::getAlignment() const
}
CHeroClass::CHeroClass()
: commander(nullptr)
: faction(0), id(0), affinity(0), defaultTavernChance(0), commander(nullptr)
{
}

View File

@ -486,12 +486,22 @@ JsonNode addMeta(JsonNode config, std::string meta)
return config;
}
CModInfo::CModInfo():
checksum(0),
enabled(false),
validation(PENDING)
{
}
CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config):
identifier(identifier),
name(config["name"].String()),
description(config["description"].String()),
dependencies(config["depends"].convertTo<std::set<std::string> >()),
conflicts(config["conflicts"].convertTo<std::set<std::string> >()),
checksum(0),
enabled(false),
validation(PENDING),
config(addMeta(config, identifier))
{
@ -554,6 +564,10 @@ void CModInfo::loadLocalData(const JsonNode & data)
CModHandler::CModHandler()
{
modules.COMMANDERS = false;
modules.STACK_ARTIFACT = false;
modules.STACK_EXP = false;
modules.MITHRIL = false;
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
{
identifiers.registerObject("core", "resource", GameConstants::RESOURCE_NAMES[i], i);

View File

@ -191,7 +191,7 @@ public:
JsonNode config;
CModInfo(){}
CModInfo();
CModInfo(std::string identifier, const JsonNode & local, const JsonNode & config);
JsonNode saveLocalData() const;

View File

@ -43,6 +43,11 @@ CPathfinder::CPathfinder(CPathsInfo & _out, CGameState * _gs, const CGHeroInstan
assert(hero);
assert(hero == getHero(hero->id));
cp = dp = nullptr;
ct = dt = nullptr;
ctObj = dtObj = nullptr;
destAction = CGPathNode::UNKNOWN;
out.hero = hero;
out.hpos = hero->getPosition(false);
if(!isInTheMap(out.hpos)/* || !gs->map->isInTheMap(dest)*/) //check input

View File

@ -26,6 +26,12 @@
const int NAMES_PER_TOWN=16; // number of town names per faction in H3 files. Json can define any number
CBuilding::CBuilding():
town(nullptr),mode(BUILD_NORMAL)
{
}
const std::string & CBuilding::Name() const
{
return name;
@ -64,6 +70,8 @@ si32 CBuilding::getDistance(BuildingID buildID) const
CFaction::CFaction()
{
town = nullptr;
index = 0;
alignment = EAlignment::NEUTRAL;
}
CFaction::~CFaction()
@ -72,6 +80,7 @@ CFaction::~CFaction()
}
CTown::CTown()
: faction(nullptr), mageLevel(0), primaryRes(0), moatDamage(0), defaultTavernChance(0)
{
}

View File

@ -56,6 +56,8 @@ public:
BUILD_GRAIL // 3 - grail - building reqires grail to be built
} mode;
CBuilding();
const std::string &Name() const;
const std::string &Description() const;

View File

@ -128,6 +128,7 @@ struct Component
h & id & subtype & val & when;
}
Component()
:id(0), subtype(0), val(0), when(0)
{
}
DLL_LINKAGE explicit Component(const CStackBasicDescriptor &stack);

View File

@ -1688,6 +1688,7 @@ DLL_LINKAGE void ObstaclesRemoved::applyGs(CGameState *gs)
DLL_LINKAGE CatapultAttack::CatapultAttack()
{
attacker = -1;
}
DLL_LINKAGE CatapultAttack::~CatapultAttack()

View File

@ -125,8 +125,6 @@ void LibClasses::init()
//FIXME: make sure that everything is ok after game restart
//TODO: This should be done every time mod config changes
IS_AI_ENABLED = false;
}
void LibClasses::clear()
@ -164,6 +162,7 @@ void LibClasses::makeNull()
LibClasses::LibClasses()
{
IS_AI_ENABLED = false;
//init pointers to handlers
makeNull();
}

View File

@ -33,8 +33,8 @@ class DLL_LINKAGE LibClasses
void callWhenDeserializing(); //should be called only by serialize !!!
void makeNull(); //sets all handler pointers to null
public:
bool IS_AI_ENABLED; //VLC is the only object visible from both CMT and GeniusAI
bool IS_AI_ENABLED; //unused?
const IBonusTypeHandler * getBth() const;
CArtHandler * arth;

View File

@ -28,6 +28,8 @@ static std::string & visitedTxt(const bool visited)
CBank::CBank()
{
daycounter = 0;
resetDuration = 0;
}
CBank::~CBank()

View File

@ -34,6 +34,13 @@ static void showInfoDialog(const CGHeroInstance* h, const ui32 txtID, const ui16
showInfoDialog(playerID,txtID,soundID);
}
CGPandoraBox::CGPandoraBox()
: hasGuardians(false), gainedExp(0), manaDiff(0), moraleDiff(0), luckDiff(0)
{
}
void CGPandoraBox::initObj(CRandomGenerator & rand)
{
blockVisit = (ID==Obj::PANDORAS_BOX); //block only if it's really pandora's box (events also derive from that class)
@ -362,6 +369,12 @@ void CGPandoraBox::afterSuccessfulVisit() const
cb->removeAfterVisit(this);
}
CGEvent::CGEvent()
: CGPandoraBox(), removeAfterVisit(false), availableFor(0), computerActivate(false), humanActivate(false)
{
}
void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
{
if(!(availableFor & (1 << h->tempOwner.getNum())))

View File

@ -35,7 +35,7 @@ public:
std::vector<SpellID> spells; //gained spells
CCreatureSet creatures; //gained creatures
CGPandoraBox() : gainedExp(0), manaDiff(0), moraleDiff(0), luckDiff(0){};
CGPandoraBox();
void initObj(CRandomGenerator & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
@ -71,7 +71,7 @@ public:
h & removeAfterVisit & availableFor & computerActivate & humanActivate;
}
CGEvent() : CGPandoraBox(){};
CGEvent();
void onHeroVisit(const CGHeroInstance * h) const override;
private:
void activated(const CGHeroInstance * h) const;

View File

@ -357,6 +357,17 @@ std::string CObjectClassesHandler::getObjectHandlerName(si32 type) const
return objects.at(type)->handlerName;
}
AObjectTypeHandler::AObjectTypeHandler():
type(-1), subtype(-1)
{
}
AObjectTypeHandler::~AObjectTypeHandler()
{
}
void AObjectTypeHandler::setType(si32 type, si32 subtype)
{
this->type = type;

View File

@ -118,8 +118,8 @@ public:
si32 type;
si32 subtype;
virtual ~AObjectTypeHandler(){}
AObjectTypeHandler();
virtual ~AObjectTypeHandler();
void setType(si32 type, si32 subtype);
void setTypeName(std::string type, std::string subtype);

View File

@ -454,6 +454,7 @@ void CRewardableObject::newTurn(CRandomGenerator & rand) const
CRewardableObject::CRewardableObject():
soundID(soundBase::invalid),
selectMode(0),
visitMode(0),
selectedReward(0),
resetDuration(0),
canRefuse(false)

View File

@ -87,6 +87,7 @@ void CTownInstanceConstructor::configureObject(CGObjectInstance * object, CRando
}
CHeroInstanceConstructor::CHeroInstanceConstructor()
:heroClass(nullptr)
{
}
@ -257,7 +258,9 @@ std::vector<const CCreature *> CDwellingInstanceConstructor::getProducedCreature
}
CBankInstanceConstructor::CBankInstanceConstructor()
: bankResetDuration(0)
{
}
void CBankInstanceConstructor::initTypeData(const JsonNode & input)