mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 08:26:39 +00:00 
			
		
		
		
	cppcheck:
[apps/esmtool/record.cpp:697]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[apps/esmtool/record.cpp:1126]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[apps/esmtool/record.cpp:1138]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[apps/niftest/niftest.cpp:36]: (performance) Function parameter 'filename' should be passed by reference.
[apps/niftest/niftest.cpp:41]: (performance) Function parameter 'filename' should be passed by reference.
[apps/opencs/model/prefs/boolsetting.cpp:25]: (warning) Possible leak in public function. The pointer 'mWidget' is not deallocated before it is allocated.
[apps/opencs/model/prefs/shortcuteventhandler.cpp:52]: (warning) Return value of std::remove() ignored. Elements remain in container.
[apps/openmw/mwstate/quicksavemanager.cpp:5]: (performance) Variable 'mSaveName' is assigned in constructor body. Consider performing initialization in initialization list.
PVS-Studio:
apps/opencs/model/filter/parser.cpp  582  warn  V560 A part of conditional expression is always true: allowPredefined.
apps/opencs/view/world/referencecreator.cpp  67  warn  V547 Expression '!errors.empty()' is always false.
apps/opencs/view/world/referencecreator.cpp  74  warn  V547 Expression '!errors.empty()' is always false.
apps/opencs/view/doc/loader.cpp  170  warn  V560 A part of conditional expression is always true: !completed.
apps/opencs/view/doc/loader.cpp  170  warn  V560 A part of conditional expression is always true: !error.empty().
apps/opencs/model/tools/pathgridcheck.cpp  32  err  V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 32, 34.
apps/opencs/model/world/refidadapterimp.cpp  1376  err  V547 Expression 'subColIndex < 3' is always true.
apps/openmw/mwgui/widgets.hpp  318  warn  V703 It is odd that the 'mEnableRepeat' field in derived class 'MWScrollBar' overwrites field in base class 'ScrollBar'. Check lines: widgets.hpp:318, MyGUI_ScrollBar.h:179.
apps/openmw/mwgui/widgets.hpp  319  warn  V703 It is odd that the 'mRepeatTriggerTime' field in derived class 'MWScrollBar' overwrites field in base class 'ScrollBar'. Check lines: widgets.hpp:319, MyGUI_ScrollBar.h:180.
apps/openmw/mwgui/widgets.hpp  320  warn  V703 It is odd that the 'mRepeatStepTime' field in derived class 'MWScrollBar' overwrites field in base class 'ScrollBar'. Check lines: widgets.hpp:320, MyGUI_ScrollBar.h:181
apps/openmw/mwmechanics/actors.cpp  1425  warn  V547 Expression '!detected' is always true.
apps/openmw/mwmechanics/character.cpp  2155  err  V547 Expression 'mode == 0' is always true.
apps/openmw/mwmechanics/character.cpp  1192  warn  V592 The expression was enclosed by parentheses twice: ((expression)). One pair of parentheses is unnecessary or misprint is present.
apps/openmw/mwmechanics/character.cpp  521  warn  V560 A part of conditional expression is always true: (idle == mIdleState).
apps/openmw/mwmechanics/pathfinding.cpp  317  err  V547 Expression 'mPath.size() >= 2' is always true.
apps/openmw/mwscript/interpretercontext.cpp  409  warn  V560 A part of conditional expression is always false: rank > 9.
apps/openmw/mwgui/windowbase.cpp  28  warn  V560 A part of conditional expression is always true: !visible.
apps/openmw/mwgui/journalwindow.cpp  561  warn  V547 Expression '!mAllQuests' is always false.
apps/openmw/mwgui/referenceinterface.cpp  18  warn  V571 Recurring check. The '!mPtr.isEmpty()' condition was already verified in line 16.
apps/openmw/mwworld/scene.cpp  463  warn  V547 Expression 'adjustPlayerPos' is always true.
apps/openmw/mwworld/worldimp.cpp  409  err  V766 An item with the same key '"sCompanionShare"' has already been added.
apps/openmw/mwworld/cellstore.cpp  691  warn  V519 The 'state.mWaterLevel' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 689, 691.
apps/openmw/mwworld/weather.cpp  1125  warn  V519 The 'mResult.mParticleEffect' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1123, 1125.
apps/openmw/mwworld/weather.cpp  1137  warn  V519 The 'mResult.mParticleEffect' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 1135, 1137.
apps/wizard/unshield/unshieldworker.cpp  475  warn  V728 An excessive check can be simplified. The '(A && B) || (!A && !B)' expression is equivalent to the 'bool(A) == bool(B)' expression.
apps/wizard/installationpage.cpp  163  warn  V735 Possibly an incorrect HTML. The "</p" closing tag was encountered, while the "</span" tag was expected.
components/fontloader/fontloader.cpp  427  err  V547 Expression 'i == 1' is always true.
components/nifosg/nifloader.cpp  282  warn  V519 The 'created' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 278, 282.
components/esm/loadregn.cpp  119  err  V586 The 'clear' function is called twice for deallocation of the same resource. Check lines: 112, 119.
components/esm/cellref.cpp  178  warn  V581 The conditional expressions of the 'if' statements situated alongside each other are identical. Check lines: 175, 178.
components/esmterrain/storage.cpp  235  warn  V560 A part of conditional expression is always true: colStart == 0.
components/esmterrain/storage.cpp  237  warn  V560 A part of conditional expression is always true: rowStart == 0.
		
	
			
		
			
				
	
	
		
			232 lines
		
	
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			232 lines
		
	
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include "cellref.hpp"
 | 
						|
 | 
						|
#include <iostream>
 | 
						|
 | 
						|
#include "esmreader.hpp"
 | 
						|
#include "esmwriter.hpp"
 | 
						|
 | 
						|
void ESM::RefNum::load (ESMReader& esm, bool wide, const std::string& tag)
 | 
						|
{
 | 
						|
    if (wide)
 | 
						|
        esm.getHNT (*this, tag.c_str(), 8);
 | 
						|
    else
 | 
						|
        esm.getHNT (mIndex, tag.c_str());
 | 
						|
}
 | 
						|
 | 
						|
void ESM::RefNum::save (ESMWriter &esm, bool wide, const std::string& tag) const
 | 
						|
{
 | 
						|
    if (wide)
 | 
						|
        esm.writeHNT (tag, *this, 8);
 | 
						|
    else
 | 
						|
    {
 | 
						|
        int refNum = (mIndex & 0xffffff) | ((hasContentFile() ? mContentFile : 0xff)<<24);
 | 
						|
 | 
						|
        esm.writeHNT (tag, refNum, 4);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void ESM::CellRef::load (ESMReader& esm, bool &isDeleted, bool wideRefNum)
 | 
						|
{
 | 
						|
    loadId(esm, wideRefNum);
 | 
						|
    loadData(esm, isDeleted);
 | 
						|
}
 | 
						|
 | 
						|
void ESM::CellRef::loadId (ESMReader& esm, bool wideRefNum)
 | 
						|
{
 | 
						|
    // According to Hrnchamd, this does not belong to the actual ref. Instead, it is a marker indicating that
 | 
						|
    // the following refs are part of a "temp refs" section. A temp ref is not being tracked by the moved references system.
 | 
						|
    // Its only purpose is a performance optimization for "immovable" things. We don't need this, and it's problematic anyway,
 | 
						|
    // because any item can theoretically be moved by a script.
 | 
						|
    if (esm.isNextSub ("NAM0"))
 | 
						|
        esm.skipHSub();
 | 
						|
 | 
						|
    blank();
 | 
						|
 | 
						|
    mRefNum.load (esm, wideRefNum);
 | 
						|
 | 
						|
    mRefID = esm.getHNOString ("NAME");
 | 
						|
    if (mRefID.empty())
 | 
						|
    {
 | 
						|
        std::ios::fmtflags f(std::cerr.flags());
 | 
						|
        std::cerr << "Warning: got CellRef with empty RefId in " << esm.getName() << " 0x" << std::hex << esm.getFileOffset() << std::endl;
 | 
						|
        std::cerr.flags(f);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted)
 | 
						|
{
 | 
						|
    isDeleted = false;
 | 
						|
 | 
						|
    bool isLoaded = false;
 | 
						|
    while (!isLoaded && esm.hasMoreSubs())
 | 
						|
    {
 | 
						|
        esm.getSubName();
 | 
						|
        switch (esm.retSubName().intval)
 | 
						|
        {
 | 
						|
            case ESM::FourCC<'U','N','A','M'>::value:
 | 
						|
                esm.getHT(mReferenceBlocked);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'X','S','C','L'>::value:
 | 
						|
                esm.getHT(mScale);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'A','N','A','M'>::value:
 | 
						|
                mOwner = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'B','N','A','M'>::value:
 | 
						|
                mGlobalVariable = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'X','S','O','L'>::value:
 | 
						|
                mSoul = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'C','N','A','M'>::value:
 | 
						|
                mFaction = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'I','N','D','X'>::value:
 | 
						|
                esm.getHT(mFactionRank);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'X','C','H','G'>::value:
 | 
						|
                esm.getHT(mEnchantmentCharge);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'I','N','T','V'>::value:
 | 
						|
                esm.getHT(mChargeInt);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'N','A','M','9'>::value:
 | 
						|
                esm.getHT(mGoldValue);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'D','O','D','T'>::value:
 | 
						|
                esm.getHT(mDoorDest);
 | 
						|
                mTeleport = true;
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'D','N','A','M'>::value:
 | 
						|
                mDestCell = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'F','L','T','V'>::value:
 | 
						|
                esm.getHT(mLockLevel);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'K','N','A','M'>::value:
 | 
						|
                mKey = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'T','N','A','M'>::value:
 | 
						|
                mTrap = esm.getHString();
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'D','A','T','A'>::value:
 | 
						|
                esm.getHT(mPos, 24);
 | 
						|
                break;
 | 
						|
            case ESM::FourCC<'N','A','M','0'>::value:
 | 
						|
                esm.skipHSub();
 | 
						|
                break;
 | 
						|
            case ESM::SREC_DELE:
 | 
						|
                esm.skipHSub();
 | 
						|
                isDeleted = true;
 | 
						|
                break;
 | 
						|
            default:
 | 
						|
                esm.cacheSubName();
 | 
						|
                isLoaded = true;
 | 
						|
                break;
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory, bool isDeleted) const
 | 
						|
{
 | 
						|
    mRefNum.save (esm, wideRefNum);
 | 
						|
 | 
						|
    esm.writeHNCString("NAME", mRefID);
 | 
						|
 | 
						|
    if (isDeleted) {
 | 
						|
        esm.writeHNCString("DELE", "");
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    if (mScale != 1.0) {
 | 
						|
        esm.writeHNT("XSCL", mScale);
 | 
						|
    }
 | 
						|
 | 
						|
    esm.writeHNOCString("ANAM", mOwner);
 | 
						|
    esm.writeHNOCString("BNAM", mGlobalVariable);
 | 
						|
    esm.writeHNOCString("XSOL", mSoul);
 | 
						|
 | 
						|
    esm.writeHNOCString("CNAM", mFaction);
 | 
						|
    if (mFactionRank != -2) {
 | 
						|
        esm.writeHNT("INDX", mFactionRank);
 | 
						|
    }
 | 
						|
 | 
						|
    if (mEnchantmentCharge != -1)
 | 
						|
        esm.writeHNT("XCHG", mEnchantmentCharge);
 | 
						|
 | 
						|
    if (mChargeInt != -1)
 | 
						|
        esm.writeHNT("INTV", mChargeInt);
 | 
						|
 | 
						|
    if (mGoldValue != 1) {
 | 
						|
        esm.writeHNT("NAM9", mGoldValue);
 | 
						|
    }
 | 
						|
 | 
						|
    if (!inInventory && mTeleport)
 | 
						|
    {
 | 
						|
        esm.writeHNT("DODT", mDoorDest);
 | 
						|
        esm.writeHNOCString("DNAM", mDestCell);
 | 
						|
    }
 | 
						|
 | 
						|
    if (!inInventory && mLockLevel != 0) {
 | 
						|
        esm.writeHNT("FLTV", mLockLevel);
 | 
						|
    }
 | 
						|
 | 
						|
    if (!inInventory)
 | 
						|
    {
 | 
						|
        esm.writeHNOCString ("KNAM", mKey);
 | 
						|
        esm.writeHNOCString ("TNAM", mTrap);
 | 
						|
    }
 | 
						|
 | 
						|
    if (mReferenceBlocked != -1)
 | 
						|
        esm.writeHNT("UNAM", mReferenceBlocked);
 | 
						|
 | 
						|
    if (!inInventory)
 | 
						|
        esm.writeHNT("DATA", mPos, 24);
 | 
						|
}
 | 
						|
 | 
						|
void ESM::CellRef::blank()
 | 
						|
{
 | 
						|
    mRefNum.unset();
 | 
						|
    mRefID.clear();
 | 
						|
    mScale = 1;
 | 
						|
    mOwner.clear();
 | 
						|
    mGlobalVariable.clear();
 | 
						|
    mSoul.clear();
 | 
						|
    mFaction.clear();
 | 
						|
    mFactionRank = -2;
 | 
						|
    mChargeInt = -1;
 | 
						|
    mChargeIntRemainder = 0.0f;
 | 
						|
    mEnchantmentCharge = -1;
 | 
						|
    mGoldValue = 0;
 | 
						|
    mDestCell.clear();
 | 
						|
    mLockLevel = 0;
 | 
						|
    mKey.clear();
 | 
						|
    mTrap.clear();
 | 
						|
    mReferenceBlocked = -1;
 | 
						|
    mTeleport = false;
 | 
						|
 | 
						|
    for (int i=0; i<3; ++i)
 | 
						|
    {
 | 
						|
        mDoorDest.pos[i] = 0;
 | 
						|
        mDoorDest.rot[i] = 0;
 | 
						|
        mPos.pos[i] = 0;
 | 
						|
        mPos.rot[i] = 0;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
bool ESM::operator== (const RefNum& left, const RefNum& right)
 | 
						|
{
 | 
						|
    return left.mIndex==right.mIndex && left.mContentFile==right.mContentFile;
 | 
						|
}
 | 
						|
 | 
						|
bool ESM::operator< (const RefNum& left, const RefNum& right)
 | 
						|
{
 | 
						|
    if (left.mIndex<right.mIndex)
 | 
						|
        return true;
 | 
						|
 | 
						|
    if (left.mIndex>right.mIndex)
 | 
						|
        return false;
 | 
						|
 | 
						|
    return left.mContentFile<right.mContentFile;
 | 
						|
}
 |