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 17:48:18 +03:00
parent f11c54b5e9
commit c4ab962cc0
15 changed files with 116 additions and 93 deletions

View File

@ -36,7 +36,7 @@
#define LOGFL(text, formattingEl) print(boost::str(boost::format(text) % formattingEl))
CBattleAI::CBattleAI(void)
: side(-1)
: side(-1), wasWaitingForRealize(false), wasUnlockingGs(false)
{
}

View File

@ -83,6 +83,7 @@ struct SectorMap
Sector()
{
id = -1;
water = false;
}
};

View File

@ -18,7 +18,9 @@ CClientState * CCS = nullptr;
CGameInfo::CGameInfo()
{
generaltexth = nullptr;
mh = nullptr;
townh = nullptr;
}
void CGameInfo::setFromLib()

View File

@ -620,6 +620,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
if (screenType == CMenuScreen::campaignList)
{
opt = nullptr;
randMapTab = nullptr;
}
else
{
@ -3912,6 +3913,7 @@ CSavingScreen::~CSavingScreen()
ISelectionScreenInfo::ISelectionScreenInfo(const std::map<ui8, std::string> *Names /*= nullptr*/)
{
multiPlayer = CMenuScreen::SINGLE_PLAYER;
screenType = CMenuScreen::mainMenu;
assert(!SEL);
SEL = this;
current = nullptr;
@ -4102,6 +4104,8 @@ void StartWithCurrentSettings::apply(CSelectionScreen *selScreen)
CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config )
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
pos.x += config["x"].Float();
pos.y += config["y"].Float();
pos.w = 200;
@ -4110,24 +4114,23 @@ CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config )
campFile = config["file"].String();
video = config["video"].String();
OBJ_CONSTRUCTION_CAPTURING_ALL;
status = config["open"].Bool() ? CCampaignScreen::ENABLED : CCampaignScreen::DISABLED;
CCampaignHeader header = CCampaignHandler::getHeader(campFile);
hoverText = header.name;
hoverLabel = nullptr;
if (status != CCampaignScreen::DISABLED)
{
addUsedEvents(LCLICK | HOVER);
image = new CPicture(config["image"].String());
new CPicture(config["image"].String());
hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, Colors::YELLOW, "");
parent->addChild(hoverLabel);
}
if (status == CCampaignScreen::COMPLETED)
checkMark = new CPicture("CAMPCHK");
new CPicture("CAMPCHK");
}
void CCampaignScreen::CCampaignButton::clickLeft(tribool down, bool previousState)
@ -4142,10 +4145,13 @@ void CCampaignScreen::CCampaignButton::clickLeft(tribool down, bool previousStat
void CCampaignScreen::CCampaignButton::hover(bool on)
{
if (on)
hoverLabel->setText(hoverText); // Shows the name of the campaign when you get into the bounds of the button
else
hoverLabel->setText(" ");
if (hoverLabel)
{
if (on)
hoverLabel->setText(hoverText); // Shows the name of the campaign when you get into the bounds of the button
else
hoverLabel->setText(" ");
}
}
void CCampaignScreen::CCampaignButton::show(SDL_Surface * to)
@ -4198,7 +4204,7 @@ CCampaignScreen::CCampaignScreen(const JsonNode &config)
if (!config["exitbutton"].isNull())
{
back = createExitButton(config["exitbutton"]);
CButton * back = createExitButton(config["exitbutton"]);
back->hoverable = true;
}

View File

@ -129,7 +129,6 @@ class InfoCard : public CIntObject
std::shared_ptr<CAnimation> sFlags;
public:
CPicture *bg;
CMenuScreen::EState type;
bool network;
bool chatOn; //if chat is shown, then description is hidden
@ -554,9 +553,6 @@ private:
class CCampaignButton : public CIntObject
{
private:
CPicture *image;
CPicture *checkMark;
CLabel *hoverLabel;
CampaignStatus status;
@ -572,7 +568,6 @@ private:
void show(SDL_Surface * to) override;
};
CButton *back;
std::vector<CCampaignButton*> campButtons;
std::vector<CPicture*> images;

View File

@ -49,13 +49,20 @@ static si64 lodSeek(void * opaque, si64 pos, int whence)
CVideoPlayer::CVideoPlayer()
{
stream = -1;
format = nullptr;
frame = nullptr;
codecContext = nullptr;
codec = nullptr;
frame = nullptr;
sws = nullptr;
context = nullptr;
texture = nullptr;
dest = nullptr;
context = nullptr;
destRect = genRect(0,0,0,0);
pos = genRect(0,0,0,0);
refreshWait = 0;
refreshCount = 0;
doLoop = false;
// Register codecs. TODO: May be overkill. Should call a
// combination of av_register_input_format() /
@ -143,17 +150,17 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
}
// Allocate video frame
frame = av_frame_alloc();
//setup scaling
if(scale)
{
pos.w = screen->w;
pos.w = screen->w;
pos.h = screen->h;
}
else
{
pos.w = codecContext->width;
pos.h = codecContext->height;
pos.w = codecContext->width;
pos.h = codecContext->height;
}
// Allocate a place to put our YUV image on that screen
@ -174,7 +181,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
if (texture)
{ // Convert the image into YUV format that SDL uses
sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,
sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,
pos.w, pos.h,
AV_PIX_FMT_YUV420P,
SWS_BICUBIC, nullptr, nullptr, nullptr);
@ -205,8 +212,8 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
}
}
sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,
pos.w, pos.h, screenFormat,
sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,
pos.w, pos.h, screenFormat,
SWS_BICUBIC, nullptr, nullptr, nullptr);
}
@ -357,7 +364,7 @@ void CVideoPlayer::close()
if (frame)
{
av_frame_free(&frame);//will be set to null
av_frame_free(&frame);//will be set to null
}
if (codec)

View File

@ -133,13 +133,13 @@ bool CAttackAnimation::checkInitialConditions()
}
CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender)
: CBattleStackAnimation(_owner, attacker),
soundPlayed(false),
dest(_dest), attackedStack(defender), attackingStack(attacker)
: CBattleStackAnimation(_owner, attacker),
shooting(false), group(CCreatureAnim::SHOOT_FRONT),
soundPlayed(false),
dest(_dest), attackedStack(defender), attackingStack(attacker)
{
assert(attackingStack && "attackingStack is nullptr in CBattleAttack::CBattleAttack !\n");
bool isCatapultAttack = attackingStack->hasBonusOfType(Bonus::CATAPULT)
bool isCatapultAttack = attackingStack->hasBonusOfType(Bonus::CATAPULT)
&& owner->getCurrentPlayerInterface()->cb->battleHexToWallPart(_dest) >= 0;
assert(attackedStack || isCatapultAttack);
@ -150,7 +150,7 @@ CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attac
CDefenceAnimation::CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner)
: CBattleStackAnimation(_owner, _attackedInfo.defender),
attacker(_attackedInfo.attacker), rangedAttack(_attackedInfo.indirectAttack),
killed(_attackedInfo.killed)
killed(_attackedInfo.killed), timeToWait(0)
{
logAnim->debugStream() << "Created defence anim for " << _attackedInfo.defender->getName();
}
@ -198,7 +198,7 @@ bool CDefenceAnimation::init()
//unit reversed
if(rangedAttack) //delay hit animation
{
{
for(std::list<ProjectileInfo>::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it)
{
if(it->creID == attacker->getCreature()->idNumber)
@ -243,7 +243,7 @@ CCreatureAnim::EAnimType CDefenceAnimation::getMyAnimType()
{
if(killed)
return CCreatureAnim::DEATH;
if (vstd::contains(stack->state, EBattleStackState::DEFENDING_ANIM))
return CCreatureAnim::DEFENCE;
@ -281,7 +281,7 @@ void CDefenceAnimation::endAnim()
delete this;
}
CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames)
CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames)
: CBattleAnimation(_owner), counter(0), howMany(howManyFrames)
{
logAnim->debugStream() << "Created dummy animation for " << howManyFrames <<" frames";
@ -314,7 +314,7 @@ bool CMeleeAttackAnimation::init()
if(!attackingStack || myAnim->isDead())
{
endAnim();
return false;
}
@ -370,7 +370,7 @@ bool CMeleeAttackAnimation::init()
}
CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked)
: CAttackAnimation(_owner, attacker, _dest, _attacked)
: CAttackAnimation(_owner, attacker, _dest, _attacked)
{
logAnim->debugStream() << "Created melee attack anim for " << attacker->getName();
}
@ -534,7 +534,7 @@ CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_
}
CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile)
: CBattleStackAnimation(_owner, _stack), destinationTile(destTile)
: CBattleStackAnimation(_owner, _stack), destinationTile(destTile)
{
logAnim->debugStream() << "Created movement end anim for " << stack->getName();
}
@ -573,7 +573,7 @@ void CMovementEndAnimation::endAnim()
}
CMovementStartAnimation::CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack)
: CBattleStackAnimation(_owner, _stack)
: CBattleStackAnimation(_owner, _stack)
{
logAnim->debugStream() << "Created movement start anim for " << stack->getName();
}
@ -776,7 +776,7 @@ bool CShootingAnimation::init()
spi.dx = (destPos.x - spi.x) / spi.lastStep;
spi.dy = (destPos.y - spi.y) / spi.lastStep;
}
else
else
{
// Catapult attack
spi.catapultInfo.reset(new CatapultProjectileInfo(Point(spi.x, spi.y), destPos));
@ -885,7 +885,7 @@ CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::str
CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip, bool _alignToBottom)
:CBattleAnimation(_owner), effect(-1), destTile(_destTile), customAnim(_customAnim), x(-1), y(-1), dx(0), dy(0), Vflip(_Vflip), alignToBottom(_alignToBottom)
{
logAnim->debugStream() << "Created spell anim for " << customAnim;
logAnim->debugStream() << "Created spell anim for " << customAnim;
}
@ -893,21 +893,21 @@ bool CSpellEffectAnimation::init()
{
if(!isEarliest(true))
return false;
if(customAnim.empty() && effect != ui32(-1) && !graphics->battleACToDef[effect].empty())
{
{
customAnim = graphics->battleACToDef[effect][0];
}
if(customAnim.empty())
{
endAnim();
return false;
return false;
}
const bool areaEffect = (!destTile.isValid() && x == -1 && y == -1);
if(areaEffect) //f.e. armageddon
if(areaEffect) //f.e. armageddon
{
CDefHandler * anim = CDefHandler::giveDef(customAnim);
@ -934,7 +934,7 @@ bool CSpellEffectAnimation::init()
owner->battleEffects.push_back(be);
}
}
delete anim;
}
else // Effects targeted at a specific creature/hex.
@ -956,9 +956,9 @@ bool CSpellEffectAnimation::init()
be.currentFrame = 0;
be.maxFrame = be.anim->ourImages.size();
//todo: lightning anim frame count override
// if(effect == 1)
// be.maxFrame = 3;
@ -970,7 +970,7 @@ bool CSpellEffectAnimation::init()
{
be.x = x;
}
if(y == -1)
{
if(alignToBottom)
@ -993,7 +993,7 @@ bool CSpellEffectAnimation::init()
owner->battleEffects.push_back(be);
}
//battleEffects
//battleEffects
return true;
}

View File

@ -1557,8 +1557,7 @@ bool CFadeAnimation::isFinished() const
}
CFadeAnimation::CFadeAnimation()
: fadingSurface(nullptr),
fading(false),
: delta(0), fadingSurface(nullptr), fading(false), fadingCounter(0), shouldFreeSurface(false),
fadingMode(EMode::NONE)
{
}

View File

@ -170,15 +170,15 @@ void CGuiHandler::updateTime()
void CGuiHandler::handleEvents()
{
//player interface may want special event handling
//player interface may want special event handling
if(nullptr != LOCPLINT && LOCPLINT->capturedAllEvents())
return;
boost::unique_lock<boost::mutex> lock(eventsM);
boost::unique_lock<boost::mutex> lock(eventsM);
while(!events.empty())
{
SDL_Event ev = events.front();
events.pop();
events.pop();
this->handleEvent(&ev);
}
}
@ -286,14 +286,14 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
{
it->textInputed(sEvent->text);
}
}
}
else if(sEvent->type == SDL_TEXTEDITING)
{
for(auto it : textInterested)
{
it->textEdited(sEvent->edit);
}
}
}
//todo: muiltitouch
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
{
@ -398,9 +398,9 @@ void CGuiHandler::renderFrame()
// Updating GUI requires locking pim mutex (that protects screen and GUI state).
// During game:
// When ending the game, the pim mutex might be hold by other thread,
// that will notify us about the ending game by setting terminate_cond flag.
//in PreGame terminate_cond stay false
// that will notify us about the ending game by setting terminate_cond flag.
//in PreGame terminate_cond stay false
bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded
while(!terminate_cond.get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate
boost::this_thread::sleep(boost::posix_time::milliseconds(15));
@ -412,25 +412,25 @@ void CGuiHandler::renderFrame()
if(nullptr != curInt)
curInt->update();
if (settings["general"]["showfps"].Bool())
drawFPSCounter();
drawFPSCounter();
// draw the mouse cursor and update the screen
CCS->curh->render();
if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr))
logGlobal->errorStream() << __FUNCTION__ << " SDL_RenderCopy " << SDL_GetError();
SDL_RenderPresent(mainRenderer);
}
SDL_RenderPresent(mainRenderer);
}
mainFPSmng->framerateDelay(); // holds a constant FPS
mainFPSmng->framerateDelay(); // holds a constant FPS
}
CGuiHandler::CGuiHandler()
:lastClick(-500, -500)
: lastClick(-500, -500),lastClickTime(0), defActionsDef(0), captureChildren(false)
{
curInt = nullptr;
current = nullptr;
@ -439,7 +439,7 @@ CGuiHandler::CGuiHandler()
// Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate
mainFPSmng = new CFramerateManager(48);
//do not init CFramerateManager here --AVS
terminate_cond.set(false);
}
@ -477,7 +477,7 @@ SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key)
return SDLK_KP_6;
default:
throw std::runtime_error("Wrong key!");
}
}
}
SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key)
@ -495,7 +495,7 @@ SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key)
REMOVE_KP(6)
REMOVE_KP(7)
REMOVE_KP(8)
REMOVE_KP(9)
REMOVE_KP(9)
REMOVE_KP(PERIOD)
REMOVE_KP(MINUS)
REMOVE_KP(PLUS)
@ -546,6 +546,8 @@ CFramerateManager::CFramerateManager(int rate)
this->fps = 0;
this->accumulatedFrames = 0;
this->accumulatedTime = 0;
this->lastticks = 0;
this->timeElapsed = 0;
}
void CFramerateManager::init()
@ -557,23 +559,23 @@ void CFramerateManager::framerateDelay()
{
ui32 currentTicks = SDL_GetTicks();
timeElapsed = currentTicks - lastticks;
// FPS is higher than it should be, then wait some time
if (timeElapsed < rateticks)
{
SDL_Delay(ceil(this->rateticks) - timeElapsed);
}
accumulatedTime += timeElapsed;
accumulatedFrames++;
if(accumulatedFrames >= 100)
{
//about 2 second should be passed
fps = ceil(1000.0 / (accumulatedTime/accumulatedFrames));
fps = ceil(1000.0 / (accumulatedTime/accumulatedFrames));
accumulatedTime = 0;
accumulatedFrames = 0;
};
accumulatedFrames = 0;
};
currentTicks = SDL_GetTicks();
// recalculate timeElapsed for external calls via getElapsed()

View File

@ -49,11 +49,11 @@ public:
private:
typedef std::list<CIntObject*> CIntObjectList;
//active GUI elements (listening for events
CIntObjectList lclickable,
rclickable,
hoverable,
CIntObjectList lclickable,
rclickable,
hoverable,
keyinterested,
motioninterested,
timeinterested,
@ -61,12 +61,12 @@ private:
doubleClickInterested,
textInterested;
void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);
void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);
public:
void handleElementActivate(CIntObject * elem, ui16 activityFlag);
void handleElementDeActivate(CIntObject * elem, ui16 activityFlag);
public:
//objs to blit
std::vector<IShowable*> objsToBlit;
@ -77,9 +77,13 @@ public:
Point lastClick;
unsigned lastClickTime;
ui8 defActionsDef; //default auto actions
bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
std::list<CIntObject *> createdObj; //stack of objs being created
CGuiHandler();
~CGuiHandler();
void renderFrame();
void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
@ -99,9 +103,6 @@ public:
void fakeMouseMove();
void breakEventHandling(); //current event won't be propagated anymore
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
ui8 defActionsDef; //default auto actions
ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
std::list<CIntObject *> createdObj; //stack of objs being created
static SDL_Keycode arrowToNum(SDL_Keycode key); //converts arrow key to according numpad key
static SDL_Keycode numToDigit(SDL_Keycode key);//converts numpad digit key to normal digit key
@ -109,7 +110,7 @@ public:
static bool isArrowKey(SDL_Keycode key);
static bool amIGuiThread();
static void pushSDLEvent(int type, int usercode = 0);
static CondSh<bool> terminate_cond; // confirm termination
};

View File

@ -1377,6 +1377,9 @@ CMapHandler::CMapHandler()
worldViewBlitter = new CMapWorldViewBlitter(this);
puzzleViewBlitter = new CMapPuzzleViewBlitter(this);
fadeAnimCounter = 0;
map = nullptr;
tilesW = tilesH = 0;
offsetX = offsetY = 0;
egdeAnimation = make_unique<CAnimation>("EDG");
egdeAnimation->preload();
@ -1413,6 +1416,11 @@ void CMapHandler::discardWorldViewCache()
cache.discardWorldViewCache();
}
CMapHandler::CMapCache::CMapCache()
{
worldViewCachedScale = 0;
}
void CMapHandler::CMapCache::discardWorldViewCache()
{
for(auto & cache : data)

View File

@ -162,6 +162,7 @@ class CMapHandler
std::array< std::map<intptr_t, std::unique_ptr<IImage>>, (ui8)EMapCacheType::AFTER_LAST> data;
float worldViewCachedScale;
public:
CMapCache();
/// destroys all cached data (frees surfaces)
void discardWorldViewCache();
/// updates scale and determines if currently cached data is still valid

View File

@ -199,9 +199,6 @@ class CSlider : public CIntObject
int capacity;//how many elements can be active at same time (e.g. hero list = 5)
int positions; //number of highest position (0 if there is only one)
bool horizontal;
bool wheelScrolling;
bool keyScrolling;
int amount; //total amount of elements (e.g. hero list = 0-8)
int value; //first active element
int scrollStep; // how many elements will be scrolled via one click, default = 1

View File

@ -1329,6 +1329,7 @@ bool IPropagator::shouldBeAttached(CBonusSystemNode *dest)
}
CPropagatorNodeType::CPropagatorNodeType()
:nodeType(0)
{
}
@ -1349,6 +1350,7 @@ CreatureNativeTerrainLimiter::CreatureNativeTerrainLimiter(int TerrainType)
}
CreatureNativeTerrainLimiter::CreatureNativeTerrainLimiter()
: terrainType(-1)
{
}
@ -1366,6 +1368,7 @@ CreatureFactionLimiter::CreatureFactionLimiter(int Faction)
}
CreatureFactionLimiter::CreatureFactionLimiter()
: faction(-1)
{
}
@ -1376,6 +1379,7 @@ int CreatureFactionLimiter::limit(const BonusLimitationContext &context) const
}
CreatureAlignmentLimiter::CreatureAlignmentLimiter()
: alignment(-1)
{
}

View File

@ -142,7 +142,7 @@ public:
EBonusType bonusType;
ui16 bonusID; //ID of skill/spell
CGScholar() : bonusType(EBonusType::RANDOM){};
CGScholar() : bonusType(EBonusType::RANDOM),bonusID(0){};
void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override;
template <typename Handler> void serialize(Handler &h, const int version)