From 1bb82c710c1081d99c3b53467124973bd0f1a4f5 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 14 Aug 2014 18:55:54 +0200 Subject: [PATCH] Fix use of uninitialized memory in AiWander::init --- apps/openmw/mwmechanics/aiwander.cpp | 20 +++++++++++--------- apps/openmw/mwmechanics/aiwander.hpp | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index 3b093d6f6..6b73c9eb4 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -35,6 +35,8 @@ namespace MWMechanics void AiWander::init() { + // NOTE: mDistance and mDuration must be set already + mCellX = std::numeric_limits::max(); mCellY = std::numeric_limits::max(); mXCell = 0; @@ -47,7 +49,7 @@ namespace MWMechanics mRotate = false; mTargetAngle = 0; mSaidGreeting = Greet_None; - greetingTimer = 0; + mGreetingTimer = 0; mHasReturnPosition = false; mReturnPosition = Ogre::Vector3(0,0,0); @@ -430,19 +432,19 @@ namespace MWMechanics { if ((playerDistSqr <= helloDistance*helloDistance) && MWBase::Environment::get().getWorld()->getLOS(player, actor) && MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, actor)) - greetingTimer++; + mGreetingTimer++; - if (greetingTimer >= GREETING_SHOULD_START) + if (mGreetingTimer >= GREETING_SHOULD_START) { mSaidGreeting = Greet_InProgress; MWBase::Environment::get().getDialogueManager()->say(actor, "hello"); - greetingTimer = 0; + mGreetingTimer = 0; } } if(mSaidGreeting == Greet_InProgress) { - greetingTimer++; + mGreetingTimer++; if(mWalking) { @@ -470,10 +472,10 @@ namespace MWMechanics } } - if (greetingTimer >= GREETING_SHOULD_END) + if (mGreetingTimer >= GREETING_SHOULD_END) { mSaidGreeting = Greet_Done; - greetingTimer = 0; + mGreetingTimer = 0; } } @@ -680,8 +682,6 @@ namespace MWMechanics AiWander::AiWander (const ESM::AiSequence::AiWander* wander) { - init(); - mDistance = wander->mData.mDistance; mDuration = wander->mData.mDuration; mStartTime = MWWorld::TimeStamp(wander->mStartTime); @@ -690,6 +690,8 @@ namespace MWMechanics mIdle.push_back(wander->mData.mIdle[i]); mRepeat = wander->mData.mShouldRepeat; + + init(); } } diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index 9b579b24a..59a51446e 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -36,6 +36,7 @@ namespace MWMechanics AiWander (const ESM::AiSequence::AiWander* wander); + // NOTE: mDistance and mDuration must be set already void init(); virtual AiPackage *clone() const; @@ -68,7 +69,7 @@ namespace MWMechanics Greet_Done }; GreetingState mSaidGreeting; - int greetingTimer; + int mGreetingTimer; bool mHasReturnPosition; // NOTE: Could be removed if mReturnPosition was initialized to actor position, // if we had the actor in the AiWander constructor...