Fix some static analysis issues (coverity)

moveref
scrawl 10 years ago
parent 1b9209df4a
commit f931ba2efc

@ -149,6 +149,8 @@ int extract(Bsa::BSAFile& bsa, Arguments& info);
int extractAll(Bsa::BSAFile& bsa, Arguments& info);
int main(int argc, char** argv)
{
try
{
Arguments info;
if(!parseOptions (argc, argv, info))
@ -156,16 +158,7 @@ int main(int argc, char** argv)
// Open file
Bsa::BSAFile bsa;
try
{
bsa.open(info.filename);
}
catch(std::exception &e)
{
std::cout << "ERROR reading BSA archive '" << info.filename
<< "'\nDetails:\n" << e.what() << std::endl;
return 2;
}
if (info.mode == "list")
return list(bsa, info);
@ -179,6 +172,12 @@ int main(int argc, char** argv)
return 1;
}
}
catch (std::exception& e)
{
std::cerr << "ERROR reading BSA archive\nDetails:\n" << e.what() << std::endl;
return 2;
}
}
int list(Bsa::BSAFile& bsa, Arguments& info)
{
@ -189,9 +188,11 @@ int list(Bsa::BSAFile& bsa, Arguments& info)
if(info.longformat)
{
// Long format
std::ios::fmtflags f(std::cout.flags());
std::cout << std::setw(50) << std::left << files[i].name;
std::cout << std::setw(8) << std::left << std::dec << files[i].fileSize;
std::cout << "@ 0x" << std::hex << files[i].offset << std::endl;
std::cout.flags(f);
}
else
std::cout << files[i].name << std::endl;

@ -202,6 +202,8 @@ int clone(Arguments& info);
int comp(Arguments& info);
int main(int argc, char**argv)
{
try
{
Arguments info;
if(!parseOptions (argc, argv, info))
@ -218,6 +220,12 @@ int main(int argc, char**argv)
std::cout << "Invalid or no mode specified, dying horribly. Have a nice day." << std::endl;
return 1;
}
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 1;
}
return 0;
}
@ -273,8 +281,10 @@ void printRaw(ESM::ESMReader &esm)
esm.getSubName();
esm.skipHSub();
n = esm.retSubName();
std::ios::fmtflags f(std::cout.flags());
std::cout << " " << n.toString() << " - " << esm.getSubSize()
<< " bytes @ 0x" << std::hex << offs << "\n";
std::cout.flags(f);
}
}
}

@ -14,6 +14,8 @@
#include "maindialog.hpp"
int main(int argc, char *argv[])
{
try
{
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
SDL_SetMainReady();
@ -65,3 +67,9 @@ int main(int argc, char *argv[])
SDL_Quit();
return returnValue;
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 0;
}
}

@ -56,6 +56,9 @@ int wmain(int argc, wchar_t *wargv[]) {
char **argv = converter.get();
boost::filesystem::path::imbue(boost::locale::generator().generate(""));
#endif
try
{
bpo::options_description desc("Syntax: mwiniimporter <options> inifile configfile\nAllowed options");
bpo::positional_options_description p_desc;
desc.add_options()
@ -76,25 +79,12 @@ int wmain(int argc, wchar_t *wargv[]) {
bpo::variables_map vm;
try
{
bpo::parsed_options parsed = bpo::command_line_parser(argc, argv)
.options(desc)
.positional(p_desc)
.run();
bpo::store(parsed, vm);
}
catch(boost::program_options::unknown_option & x)
{
std::cerr << "ERROR: " << x.what() << std::endl;
return false;
}
catch(boost::program_options::invalid_command_line_syntax & x)
{
std::cerr << "ERROR: " << x.what() << std::endl;
return false;
}
if(vm.count("help") || !vm.count("ini") || !vm.count("cfg")) {
std::cout << desc;
@ -143,6 +133,10 @@ int wmain(int argc, wchar_t *wargv[]) {
std::cout << "write to: " << outputFile << std::endl;
bfs::ofstream file((bfs::path(outputFile)));
importer.writeToFile(file, cfg);
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
}
return 0;
}

@ -45,6 +45,8 @@ class Application : public QApplication
};
int main(int argc, char *argv[])
{
try
{
Q_INIT_RESOURCE (resources);
@ -87,6 +89,12 @@ int main(int argc, char *argv[])
}
shinyFactory = editor.setupGraphics();
return editor.run();
}
catch (std::exception& e)
{
std::cerr << "ERROR: " << e.what() << std::endl;
return 0;
}
}

@ -18,7 +18,7 @@
#include "adjusterwidget.hpp"
CSVDoc::FileDialog::FileDialog(QWidget *parent) :
QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0), mDialogBuilt(false)
QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0), mDialogBuilt(false), mAction(ContentAction_Undefined)
{
ui.setupUi (this);
resize(400, 400);

@ -61,7 +61,7 @@ bool CSVRender::Cell::addObjects (int start, int end)
CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
const std::string& id, boost::shared_ptr<CSVWorld::PhysicsSystem> physics, const Ogre::Vector3& origin)
: mData (data), mId (Misc::StringUtils::lowerCase (id)), mSceneMgr(sceneManager), mPhysics(physics)
: mData (data), mId (Misc::StringUtils::lowerCase (id)), mSceneMgr(sceneManager), mPhysics(physics), mX(0), mY(0)
{
mCellNode = sceneManager->getRootSceneNode()->createChildSceneNode();
mCellNode->setPosition (origin);
@ -76,16 +76,15 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
const CSMWorld::IdCollection<CSMWorld::Land>& land = mData.getLand();
int landIndex = land.searchId(mId);
if (landIndex != -1)
{
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
if(esmLand)
{
mTerrain.reset(new Terrain::TerrainGrid(sceneManager, new TerrainStorage(mData), Element_Terrain, true,
Terrain::Align_XY));
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
mTerrain->loadCell(esmLand->mX,
esmLand->mY);
if(esmLand)
{
float verts = ESM::Land::LAND_SIZE;
float worldsize = ESM::Land::REAL_SIZE;
mX = esmLand->mX;
@ -98,6 +97,7 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
CSVRender::Cell::~Cell()
{
if (mTerrain.get())
mPhysics->removeHeightField(mSceneMgr, mX, mY);
for (std::map<std::string, Object *>::iterator iter (mObjects.begin());

@ -346,7 +346,7 @@ namespace CSVRender
//plane X, upvector Y, mOffset x : x-z plane, wheel closer/further
std::pair<Ogre::Vector3, Ogre::Vector3> MouseState::planeAxis()
{
bool screenCoord = true;
const bool screenCoord = true;
Ogre::Vector3 dir = getCamera()->getDerivedDirection();
QString wheelDir = "Closer/Further";

@ -639,7 +639,8 @@ namespace
MyGUI::Vertex* vertices, RenderXform const & renderXform) :
mZ(Z), mOrigin (left, top),
mFont (font), mVertices (vertices),
mRenderXform (renderXform)
mRenderXform (renderXform),
mC(0)
{
mVertexColourType = MyGUI::RenderManager::getInstance().getVertexFormat();
}

@ -770,6 +770,7 @@ namespace MWGui
SelectSkillDialog::SelectSkillDialog()
: WindowModal("openmw_chargen_select_skill.layout")
, mSkillId(ESM::Skill::Block)
{
// Centre dialog
center();

@ -60,7 +60,7 @@ void ItemView::layoutWidgets()
int rows = maxHeight/42;
rows = std::max(rows, 1);
bool showScrollbar = std::ceil(dragArea->getChildCount()/float(rows)) > mScrollView->getWidth()/42;
bool showScrollbar = int(std::ceil(dragArea->getChildCount()/float(rows))) > mScrollView->getWidth()/42;
if (showScrollbar)
maxHeight -= 18;

@ -176,6 +176,8 @@ namespace MWGui
int screenHeight = viewSize.height;
mVideoBackground->setSize(screenWidth, screenHeight);
if (mVideo->getVideoHeight() > 0)
{
double imageaspect = static_cast<double>(mVideo->getVideoWidth())/mVideo->getVideoHeight();
int leftPadding = std::max(0.0, (screenWidth - screenHeight * imageaspect) / 2);
@ -183,6 +185,7 @@ namespace MWGui
mVideo->setCoord(leftPadding, topPadding,
screenWidth - leftPadding*2, screenHeight - topPadding*2);
}
mVideo->setVisible(true);
}

@ -304,7 +304,7 @@ namespace MWGui
mOkButton->setEnabled(pos != MyGUI::ITEM_NONE || mSaving);
mDeleteButton->setEnabled(pos != MyGUI::ITEM_NONE);
if (pos == MyGUI::ITEM_NONE)
if (pos == MyGUI::ITEM_NONE || !mCurrentCharacter)
{
mCurrentSlot = NULL;
mInfoText->setCaption("");

@ -26,6 +26,7 @@ namespace MWGui
Spell()
: mSelected(false)
, mActive(false)
, mType(Type_Spell)
{
}
};

@ -1691,6 +1691,8 @@ namespace MWGui
// Use black bars to correct aspect ratio
mVideoBackground->setSize(screenWidth, screenHeight);
if (mVideoWidget->getVideoHeight() > 0)
{
double imageaspect = static_cast<double>(mVideoWidget->getVideoWidth())/mVideoWidget->getVideoHeight();
int leftPadding = std::max(0.0, (screenWidth - screenHeight * imageaspect) / 2);
@ -1699,6 +1701,7 @@ namespace MWGui
mVideoWidget->setCoord(leftPadding, topPadding,
screenWidth - leftPadding*2, screenHeight - topPadding*2);
}
}
WindowModal* WindowManager::getCurrentModal() const
{

@ -286,6 +286,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name)
if (!iter->isEmpty())
newRecord.mData.mWeight += iter->get<ESM::Ingredient>()->mBase->mData.mWeight;
if (countIngredients() > 0)
newRecord.mData.mWeight /= countIngredients();
newRecord.mData.mValue = mValue;

@ -1644,7 +1644,7 @@ void CharacterController::update(float duration)
world->queueMovement(mPtr, Ogre::Vector3(0.0f));
}
if(mAnimation && !mSkipAnim)
if(!mSkipAnim)
{
Ogre::Vector3 moved = mAnimation->runAnimation(duration);
if(duration > 0.0f)
@ -1762,10 +1762,7 @@ bool CharacterController::kill()
playRandomDeath();
if(mAnimation)
{
mAnimation->disable(mCurrentIdle);
}
mIdleState = CharState_None;
mCurrentIdle.clear();

@ -687,12 +687,11 @@ namespace MWMechanics
// Failure sound
int school = 0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment->mEffects.mList.begin());
effectIt!=enchantment->mEffects.mList.end(); ++effectIt)
if (!enchantment->mEffects.mList.empty())
{
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectIt->mEffectID);
short effectId = enchantment->mEffects.mList.front().mEffectID;
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectId);
school = magicEffect->mData.mSchool;
break;
}
static const std::string schools[] = {
"alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration"

@ -330,7 +330,10 @@ namespace MWRender
void RaceSelectionPreview::updateCamera()
{
Ogre::Vector3 scale = mNode->getScale();
Ogre::Vector3 headOffset = mAnimation->getNode("Bip01 Head")->_getDerivedPosition();
Ogre::Node* headNode = mAnimation->getNode("Bip01 Head");
if (!headNode)
return;
Ogre::Vector3 headOffset = headNode->_getDerivedPosition();
headOffset = mNode->convertLocalToWorldPosition(headOffset);
mCamera->setPosition(headOffset + mPosition * scale);

@ -24,8 +24,9 @@
using namespace MWRender;
using namespace Ogre;
LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWRender::RenderingManager* rendering) :
mInterior(false)
LocalMap::LocalMap(OEngine::Render::OgreRenderer* rend, MWRender::RenderingManager* rendering)
: mInterior(false)
, mAngle(0.f)
{
mRendering = rend;
mRenderingManager = rendering;

@ -104,7 +104,7 @@ BillboardObject::BillboardObject( const String& textureName,
}
BillboardObject::BillboardObject()
: mNode(NULL), mMaterial(NULL), mEntity(NULL)
: mNode(NULL), mMaterial(NULL), mEntity(NULL), mVisibility(1.f)
{
}
@ -186,6 +186,7 @@ Moon::Moon( const String& textureName,
SceneNode* rootNode,
const std::string& material)
: BillboardObject(textureName, initialSize, position, rootNode, material)
, mType(Type_Masser)
{
setVisibility(1.0);

@ -283,10 +283,13 @@ namespace MWWorld
return position;
OEngine::Physic::PhysicActor *physicActor = engine->getCharacter(ptr.getRefData().getHandle());
if (!physicActor)
return position;
// Reset per-frame data
physicActor->setWalkingOnWater(false);
/* Anything to collide with? */
if(!physicActor || !physicActor->getCollisionMode())
if(!physicActor->getCollisionMode())
{
return position + (Ogre::Quaternion(Ogre::Radian(refpos.rot[2]), Ogre::Vector3::NEGATIVE_UNIT_Z) *
Ogre::Quaternion(Ogre::Radian(refpos.rot[0]), Ogre::Vector3::NEGATIVE_UNIT_X))

@ -630,9 +630,6 @@ namespace MWWorld
}
const ESM::Cell *searchOrCreate(int x, int y) {
ESM::Cell cell;
cell.mData.mX = x, cell.mData.mY = y;
std::pair<int, int> key(x, y);
DynamicExt::const_iterator it = mExt.find(key);
if (it != mExt.end()) {
@ -644,13 +641,15 @@ namespace MWWorld
return &dit->second;
}
ESM::Cell *newCell = new ESM::Cell;
newCell->mData.mX = x;
newCell->mData.mY = y;
mExt[std::make_pair(x, y)] = *newCell;
delete newCell;
return &mExt[std::make_pair(x, y)];
ESM::Cell newCell;
newCell.mData.mX = x;
newCell.mData.mY = y;
newCell.mData.mFlags = ESM::Cell::HasWater;
newCell.mAmbi.mAmbient = 0;
newCell.mAmbi.mSunlight = 0;
newCell.mAmbi.mFog = 0;
newCell.mAmbi.mFogDensity = 0;
return &mExt.insert(std::make_pair(key, newCell)).first->second;
}
const ESM::Cell *find(const std::string &id) const {
@ -853,6 +852,11 @@ namespace MWWorld
public:
Store<ESM::Pathgrid>()
: mCells(NULL)
{
}
void setCells(Store<ESM::Cell>& cells)
{
mCells = &cells;

@ -2554,7 +2554,7 @@ namespace MWWorld
if (!selectedSpell.empty())
{
const ESM::Spell* spell = getStore().get<ESM::Spell>().search(selectedSpell);
const ESM::Spell* spell = getStore().get<ESM::Spell>().find(selectedSpell);
// Check mana
MWMechanics::DynamicStat<float> magicka = stats.getMagicka();
@ -2641,7 +2641,7 @@ namespace MWWorld
if (!selectedSpell.empty())
{
const ESM::Spell* spell = getStore().get<ESM::Spell>().search(selectedSpell);
const ESM::Spell* spell = getStore().get<ESM::Spell>().find(selectedSpell);
// A power can be used once per 24h
if (spell->mData.mType == ESM::Spell::ST_Power)

@ -177,7 +177,6 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int
return file->fileProperty(static_cast<const EsmFile::FileProperty>(column));
return QVariant();
break;
}
case Qt::TextAlignmentRole:
@ -193,8 +192,6 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int
default:
return Qt::AlignLeft + Qt::AlignVCenter;
}
return QVariant();
break;
}
case Qt::ToolTipRole:
@ -203,7 +200,6 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int
return QVariant();
return file->toolTip();
break;
}
case Qt::CheckStateRole:
@ -212,8 +208,6 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int
return QVariant();
return mCheckStates[file->filePath()];
break;
}
case Qt::UserRole:
@ -229,7 +223,6 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int
case Qt::UserRole + 1:
return isChecked(file->filePath());
break;
}
return QVariant();
}

@ -242,6 +242,8 @@ bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref)
else
{
id.mWorldspace = Misc::StringUtils::lowerCase (mName);
id.mIndex.mX = 0;
id.mIndex.mY = 0;
}
return id;

@ -928,6 +928,8 @@ class NIFObjectLoader
particledata = static_cast<const Nif::NiAutoNormalParticles*>(partnode)->data.getPtr();
else if(partnode->recType == Nif::RC_NiRotatingParticles)
particledata = static_cast<const Nif::NiRotatingParticles*>(partnode)->data.getPtr();
else
throw std::runtime_error("Unexpected particle node type");
std::string fullname = name+"@index="+Ogre::StringConverter::toString(partnode->recIndex);
if(partnode->name.length() > 0)

@ -319,7 +319,9 @@ void Utf8Encoder::copyFromArray2(const char*& chp, char* &out)
}
}
std::ios::fmtflags f(std::cout.flags());
std::cout << "Could not find glyph " << std::hex << (int)ch << " " << (int)ch2 << " " << (int)ch3 << std::endl;
std::cout.flags(f);
*(out++) = ch; // Could not find glyph, just put whatever
}

@ -299,7 +299,7 @@ namespace ICS
{
if(it->second.find(axis) != it->second.end())
{
mControlsJoystickPOVBinderMap[deviceId].find(index)->second.erase( it->second.find(axis) );
it->second.erase( it->second.find(axis) );
}
}
}

@ -28,7 +28,9 @@ namespace SFO
mWantGrab(false),
mWantRelative(false),
mWantMouseVisible(false),
mAllowGrab(grab)
mAllowGrab(grab),
mWarpX(0),
mWarpY(0)
{
_setupOISKeys();
}
@ -117,7 +119,9 @@ namespace SFO
case SDL_CLIPBOARDUPDATE:
break; // We don't need this event, clipboard is retrieved on demand
default:
std::ios::fmtflags f(std::cerr.flags());
std::cerr << "Unhandled SDL event of type 0x" << std::hex << evt.type << std::endl;
std::cerr.flags(f);
break;
}
}

Loading…
Cancel
Save