1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-30 16:20:21 +00:00

Merge pull request #1974 from akortunov/coverity

Fix some issues found by Coverity Scan
This commit is contained in:
Bret Curtis 2018-10-25 09:42:51 +02:00 committed by GitHub
commit 375354ab6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 55 deletions

View File

@ -7,6 +7,7 @@
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/fallback/validate.hpp> #include <components/fallback/validate.hpp>
#include <components/misc/rng.hpp>
#include <components/nifosg/nifloader.hpp> #include <components/nifosg/nifloader.hpp>
#include "model/doc/document.hpp" #include "model/doc/document.hpp"
@ -355,6 +356,8 @@ int CS::Editor::run()
if (mLocal.empty()) if (mLocal.empty())
return 1; return 1;
Misc::Rng::init();
mStartup.show(); mStartup.show();
QApplication::setQuitOnLastWindowClosed (true); QApplication::setQuitOnLastWindowClosed (true);

View File

@ -190,12 +190,6 @@ namespace
{ {
} }
RemoveFinishedCallbackVisitor(int effectId)
: RemoveVisitor()
, mHasMagicEffects(false)
{
}
virtual void apply(osg::Node &node) virtual void apply(osg::Node &node)
{ {
traverse(node); traverse(node);
@ -228,9 +222,6 @@ namespace
virtual void apply(osg::Geometry&) virtual void apply(osg::Geometry&)
{ {
} }
private:
int mEffectId;
}; };
class RemoveCallbackVisitor : public RemoveVisitor class RemoveCallbackVisitor : public RemoveVisitor

View File

@ -6,6 +6,7 @@
#include <osg/Geometry> #include <osg/Geometry>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/misc/rng.hpp>
#include <components/nif/controlled.hpp> #include <components/nif/controlled.hpp>
#include <components/nif/nifkey.hpp> #include <components/nif/nifkey.hpp>
#include <components/nif/data.hpp> #include <components/nif/data.hpp>
@ -81,17 +82,17 @@ ParticleShooter::ParticleShooter(const ParticleShooter &copy, const osg::CopyOp
void ParticleShooter::shoot(osgParticle::Particle *particle) const void ParticleShooter::shoot(osgParticle::Particle *particle) const
{ {
float hdir = mHorizontalDir + mHorizontalAngle * (2.f * (std::rand() / static_cast<double>(RAND_MAX)) - 1.f); float hdir = mHorizontalDir + mHorizontalAngle * (2.f * Misc::Rng::rollClosedProbability() - 1.f);
float vdir = mVerticalDir + mVerticalAngle * (2.f * (std::rand() / static_cast<double>(RAND_MAX)) - 1.f); float vdir = mVerticalDir + mVerticalAngle * (2.f * Misc::Rng::rollClosedProbability() - 1.f);
osg::Vec3f dir = (osg::Quat(vdir, osg::Vec3f(0,1,0)) * osg::Quat(hdir, osg::Vec3f(0,0,1))) osg::Vec3f dir = (osg::Quat(vdir, osg::Vec3f(0,1,0)) * osg::Quat(hdir, osg::Vec3f(0,0,1)))
* osg::Vec3f(0,0,1); * osg::Vec3f(0,0,1);
float vel = mMinSpeed + (mMaxSpeed - mMinSpeed) * std::rand() / static_cast<float>(RAND_MAX); float vel = mMinSpeed + (mMaxSpeed - mMinSpeed) * Misc::Rng::rollClosedProbability();
particle->setVelocity(dir * vel); particle->setVelocity(dir * vel);
// Not supposed to set this here, but there doesn't seem to be a better way of doing it // Not supposed to set this here, but there doesn't seem to be a better way of doing it
particle->setLifeTime(mLifetime + mLifetimeRandom * std::rand() / static_cast<float>(RAND_MAX)); particle->setLifeTime(mLifetime + mLifetimeRandom * Misc::Rng::rollClosedProbability());
} }
GrowFadeAffector::GrowFadeAffector(float growTime, float fadeTime) GrowFadeAffector::GrowFadeAffector(float growTime, float fadeTime)
@ -277,7 +278,8 @@ void Emitter::emitParticles(double dt)
if (!mTargets.empty()) if (!mTargets.empty())
{ {
int randomRecIndex = mTargets[(std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * mTargets.size()]; int randomIndex = Misc::Rng::rollClosedProbability() * (mTargets.size() - 1);
int randomRecIndex = mTargets[randomIndex];
// we could use a map here for faster lookup // we could use a map here for faster lookup
FindGroupByRecIndex visitor(randomRecIndex); FindGroupByRecIndex visitor(randomRecIndex);

View File

@ -1046,58 +1046,35 @@ bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding )
return false; return false;
} }
const char* lastPos = buf; const char* p = buf; // the read head
const char* p = buf; char* q = buf; // the write head
const char CR = 0x0d;
const char LF = 0x0a;
buf[length] = 0; buf[length] = 0;
while( *p ) { while( *p ) {
assert( p < (buf+length) ); assert( p < (buf+length) );
if ( *p == 0xa ) { assert( q <= (buf+length) );
// Newline character. No special rules for this. Append all the characters assert( q <= p );
// since the last string, and include the newline.
data.append( lastPos, (p-lastPos+1) ); // append, include the newline
++p; // move past the newline
lastPos = p; // and point to the new buffer (may be 0)
assert( p <= (buf+length) );
}
else if ( *p == 0xd ) {
// Carriage return. Append what we have so far, then
// handle moving forward in the buffer.
if ( (p-lastPos) > 0 ) {
data.append( lastPos, p-lastPos ); // do not add the CR
}
data += (char)0xa; // a proper newline
if ( *(p+1) == 0xa ) { if ( *p == CR ) {
// Carriage return - new line sequence *q++ = LF;
p += 2; p++;
lastPos = p; if ( *p == LF ) { // check for CR+LF (and skip LF)
assert( p <= (buf+length) ); p++;
}
else {
// it was followed by something else...that is presumably characters again.
++p;
lastPos = p;
assert( p <= (buf+length) );
} }
} }
else { else {
++p; *q++ = *p++;
} }
} }
// Handle any left over characters. assert( q <= (buf+length) );
if ( p-lastPos ) { *q = 0;
data.append( lastPos, p-lastPos );
} Parse( buf, 0, encoding );
delete [] buf; delete [] buf;
buf = 0; return !Error();
Parse( data.c_str(), 0, encoding );
if ( Error() )
return false;
else
return true;
} }