diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-07-04 21:11:28 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-07-04 21:11:28 +0300 |
commit | 8dd47e51d9c318e522b21f28bc3e3935ef692056 (patch) | |
tree | 30b364f3f1b04fd31efec47332d193567894997f /src | |
parent | d1d205fbe0c2d63bbd08742c56f00852ccc0523b (diff) | |
download | manaverse-8dd47e51d9c318e522b21f28bc3e3935ef692056.tar.gz manaverse-8dd47e51d9c318e522b21f28bc3e3935ef692056.tar.bz2 manaverse-8dd47e51d9c318e522b21f28bc3e3935ef692056.tar.xz manaverse-8dd47e51d9c318e522b21f28bc3e3935ef692056.zip |
add missing checks.
also fix crash in creating character with broken data.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/charcreatedialog.cpp | 10 | ||||
-rw-r--r-- | src/gui/palette.cpp | 2 | ||||
-rw-r--r-- | src/net/ea/playerhandler.cpp | 6 | ||||
-rw-r--r-- | src/particle.cpp | 3 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 4 |
5 files changed, 18 insertions, 7 deletions
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index c32098b63..b0a7d730c 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -159,8 +159,14 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent, if (!maxHairStyle) maxHairStyle = mPlayer->getNumOfHairstyles(); - mHairStyle = (rand() % maxHairStyle) + minHairStyle; - mHairColor = (rand() % maxHairColor) + minHairColor; + if (maxHairStyle) + mHairStyle = (rand() % maxHairStyle) + minHairStyle; + else + mHairStyle = 0; + if (maxHairColor) + mHairColor = (rand() % maxHairColor) + minHairColor; + else + mHairColor = 0; mNameField->setMaximum(24); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index abd328458..1b25620a9 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -127,7 +127,7 @@ void Palette::advanceGradient() % (delay * numOfColors); const int gradIndex = elem->gradientIndex; - const int pos = gradIndex % delay; + const int pos = delay ? (gradIndex % delay) : gradIndex; int colIndex; if (delay) colIndex = gradIndex / delay; diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 5e847f88f..446766b56 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -157,7 +157,11 @@ static const char *randomDeathMessage() N_("You're pining for the fjords.") }; - const int random = static_cast<int>(rand() % (sizeof(deadMsg) + const int sz = sizeof(deadMsg); + if (!sz) + return gettext(deadMsg[0]); + + const int random = static_cast<int>(rand() % (sz / sizeof(deadMsg[0]))); return gettext(deadMsg[random]); } diff --git a/src/particle.cpp b/src/particle.cpp index 9ec83afb6..6e8ab14a7 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -205,7 +205,8 @@ bool Particle::update() } // Update child emitters - if ((mLifetimePast - 1) % Particle::emitterSkip == 0) + if (Particle::emitterSkip && (mLifetimePast - 1) + % Particle::emitterSkip == 0) { FOR_EACH (EmitterConstIterator, e, mChildEmitters) { diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 361dead4d..f54673447 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -114,8 +114,8 @@ const SoundInfo &BeingInfo::getSound(const SoundEvent event) const static SoundInfo emptySound("", 0); const SoundEvents::const_iterator i = mSounds.find(event); - return (i == mSounds.end() || !i->second) ? emptySound : - i->second->at(rand() % i->second->size()); + return (i == mSounds.end() || !i->second || i->second->empty()) + ? emptySound : i->second->at(rand() % i->second->size()); } const Attack *BeingInfo::getAttack(const int id) const |