Skip to content

Commit

Permalink
PVS-Studio pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Kawa-oneechan committed Nov 3, 2023
1 parent bb72070 commit 33f756f
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 89 deletions.
73 changes: 18 additions & 55 deletions SCICompanion/SCICompanion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,116 +302,74 @@ BOOL SCICompanionApp::InitInstance()
RUNTIME_CLASS(CResourceListDoc),
RUNTIME_CLASS(CGameExplorerFrame), // custom MDI child frame
RUNTIME_CLASS(CGameExplorerView));
if (!pDocTemplate)
return FALSE;
//KAWA: removed "if !pDocTemplate return false" because "new" would raise an exception instead.
AddDocTemplate(pDocTemplate);

appState->_pPicTemplate = new CMultiDocTemplateWithNonViews(IDR_TEXTFRAME,
RUNTIME_CLASS(CPicDoc),
RUNTIME_CLASS(CPicChildFrame), // standard MDI child frame
RUNTIME_CLASS(CPicView));
if (!appState->_pPicTemplate)
return FALSE;
//KAWA: same for the rest of 'em.
AddDocTemplate(appState->_pPicTemplate);

appState->_pVocabTemplate = new CMultiDocTemplate(IDR_VOCABFRAME,
RUNTIME_CLASS(CVocabDoc),
RUNTIME_CLASS(CVocabChildFrame),
RUNTIME_CLASS(CVocabView));
if (!appState->_pVocabTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pVocabTemplate);

appState->_pTextTemplate = new CMultiDocTemplate(IDR_TEXTFRAME,
RUNTIME_CLASS(CTextDoc),
RUNTIME_CLASS(CTextChildFrame),
RUNTIME_CLASS(CTextView));
if (!appState->_pTextTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pTextTemplate);

appState->_pSoundTemplate = new CMultiDocTemplate(IDR_TEXTFRAME,
RUNTIME_CLASS(CSoundDoc),
RUNTIME_CLASS(CSoundChildFrame),
RUNTIME_CLASS(CSoundView));
if (!appState->_pSoundTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pSoundTemplate);

appState->_pViewTemplate = new CMultiDocTemplateWithNonViews(IDR_TEXTFRAME,
RUNTIME_CLASS(CNewRasterResourceDocument),
RUNTIME_CLASS(CEditViewChildFrame),
RUNTIME_CLASS(CRasterView));
if (!appState->_pViewTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pViewTemplate);

appState->_pFontTemplate = new CMultiDocTemplateWithNonViews(IDR_TEXTFRAME,
RUNTIME_CLASS(CNewRasterResourceDocument),
RUNTIME_CLASS(CEditFontChildFrame),
RUNTIME_CLASS(CRasterView));
if (!appState->_pFontTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pFontTemplate);

appState->_pCursorTemplate = new CMultiDocTemplateWithNonViews(IDR_TEXTFRAME,
RUNTIME_CLASS(CNewRasterResourceDocument),
RUNTIME_CLASS(CCursorChildFrame),
RUNTIME_CLASS(CRasterView));
if (!appState->_pCursorTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pCursorTemplate);

appState->_pScriptTemplate = new CMultiDocTemplate(IDR_SCRIPTFRAME,
RUNTIME_CLASS(CScriptDocument),
RUNTIME_CLASS(CScriptFrame),
RUNTIME_CLASS(CScriptView));
if (!appState->_pScriptTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pScriptTemplate);

appState->_pMessageTemplate = new CMultiDocTemplateWithNonViews(IDR_TEXTFRAME,
RUNTIME_CLASS(CMessageDoc),
RUNTIME_CLASS(CMessageChildFrame),
RUNTIME_CLASS(CMessageView));
if (!appState->_pMessageTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pMessageTemplate);

appState->_pPaletteTemplate = new CMultiDocTemplate(IDR_TEXTFRAME,
RUNTIME_CLASS(CPaletteDoc),
RUNTIME_CLASS(CPaletteChildFrame),
RUNTIME_CLASS(CPaletteView));
if (!appState->_pMessageTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pPaletteTemplate);

appState->_pRoomExplorerTemplate = new CMultiDocTemplate(IDR_TEXTFRAME,
RUNTIME_CLASS(CRoomExplorerDoc),
RUNTIME_CLASS(CRoomExplorerFrame),
RUNTIME_CLASS(CRoomExplorerView));
if (!appState->_pRoomExplorerTemplate)
{
return FALSE;
}
AddDocTemplate(appState->_pRoomExplorerTemplate);

// Prof-UIS stuff
Expand All @@ -431,8 +389,11 @@ BOOL SCICompanionApp::InitInstance()

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
{
delete pMainFrame;
return FALSE;
}
m_pMainWnd = pMainFrame;

// Register a clipboard format for pic commands
Expand Down Expand Up @@ -534,11 +495,12 @@ void SCICompanionApp::_LoadSettings(BOOL fReset)
appState->_audioProcessing->AutoGain = GetProfileInt(pszRegName, TEXT("AutoGain"), appState->_audioProcessing->AutoGain);
appState->_audioProcessing->AudioDither = GetProfileInt(pszRegName, TEXT("AudioDither"), appState->_audioProcessing->AudioDither);
appState->_audioProcessing->Compression = GetProfileInt(pszRegName, TEXT("Compression"), appState->_audioProcessing->Compression);
appState->_audioProcessing->Noise.AttackTimeMS = GetProfileInt(pszRegName, TEXT("NoiseAttackTimeMS"), appState->_audioProcessing->Noise.AttackTimeMS);
appState->_audioProcessing->Noise.ReleaseTimeMS = GetProfileInt(pszRegName, TEXT("NoiseReleaseTimeMS"), appState->_audioProcessing->Noise.ReleaseTimeMS);
appState->_audioProcessing->Noise.HoldTimeMS = GetProfileInt(pszRegName, TEXT("NoiseHoldTimeMS"), appState->_audioProcessing->Noise.HoldTimeMS);
appState->_audioProcessing->Noise.OpenThresholdDB = GetProfileInt(pszRegName, TEXT("NoiseOpenThresholdDB"), appState->_audioProcessing->Noise.OpenThresholdDB);
appState->_audioProcessing->Noise.CloseThresholdDB = GetProfileInt(pszRegName, TEXT("NoiseCloseThresholdDB"), appState->_audioProcessing->Noise.CloseThresholdDB);
NoiseSettings noise = appState->_audioProcessing->Noise;
noise.AttackTimeMS = GetProfileInt(pszRegName, TEXT("NoiseAttackTimeMS"), appState->_audioProcessing->Noise.AttackTimeMS);
noise.ReleaseTimeMS = GetProfileInt(pszRegName, TEXT("NoiseReleaseTimeMS"), appState->_audioProcessing->Noise.ReleaseTimeMS);
noise.HoldTimeMS = GetProfileInt(pszRegName, TEXT("NoiseHoldTimeMS"), appState->_audioProcessing->Noise.HoldTimeMS);
noise.OpenThresholdDB = GetProfileInt(pszRegName, TEXT("NoiseOpenThresholdDB"), appState->_audioProcessing->Noise.OpenThresholdDB);
noise.CloseThresholdDB = GetProfileInt(pszRegName, TEXT("NoiseCloseThresholdDB"), appState->_audioProcessing->Noise.CloseThresholdDB);

appState->_fUseBoxEgo = GetProfileInt(pszRegName, TEXT("UseBoxEgo"), FALSE);
appState->_fScaleTracingImages = GetProfileInt(pszRegName, TEXT("ScaleTracingImages"), TRUE);
Expand Down Expand Up @@ -579,11 +541,12 @@ void SCICompanionApp::_SaveSettings()
WriteProfileInt(m_pszAppName, TEXT("AutoGain"), appState->_audioProcessing->AutoGain);
WriteProfileInt(m_pszAppName, TEXT("DetectStartEnd"), appState->_audioProcessing->DetectStartEnd);
WriteProfileInt(m_pszAppName, TEXT("Compression"), appState->_audioProcessing->Compression);
WriteProfileInt(m_pszAppName, TEXT("NoiseAttackTimeMS"), appState->_audioProcessing->Noise.AttackTimeMS);
WriteProfileInt(m_pszAppName, TEXT("NoiseReleaseTimeMS"), appState->_audioProcessing->Noise.ReleaseTimeMS);
WriteProfileInt(m_pszAppName, TEXT("NoiseHoldTimeMS"), appState->_audioProcessing->Noise.HoldTimeMS);
WriteProfileInt(m_pszAppName, TEXT("NoiseOpenThresholdDB"), appState->_audioProcessing->Noise.OpenThresholdDB);
WriteProfileInt(m_pszAppName, TEXT("NoiseCloseThresholdDB"), appState->_audioProcessing->Noise.CloseThresholdDB);
NoiseSettings noise = appState->_audioProcessing->Noise;
WriteProfileInt(m_pszAppName, TEXT("NoiseAttackTimeMS"), noise.AttackTimeMS);
WriteProfileInt(m_pszAppName, TEXT("NoiseReleaseTimeMS"), noise.ReleaseTimeMS);
WriteProfileInt(m_pszAppName, TEXT("NoiseHoldTimeMS"), noise.HoldTimeMS);
WriteProfileInt(m_pszAppName, TEXT("NoiseOpenThresholdDB"), noise.OpenThresholdDB);
WriteProfileInt(m_pszAppName, TEXT("NoiseCloseThresholdDB"), noise.CloseThresholdDB);

WriteProfileInt(m_pszAppName, TEXT("UseBoxEgo"), appState->_fUseBoxEgo);
WriteProfileInt(m_pszAppName, TEXT("ScaleTracingImages"), appState->_fScaleTracingImages);
Expand Down
16 changes: 5 additions & 11 deletions SCICompanionLib/Src/Compile/CompileInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum ProcedureType
class ISourceCodePosition
{
public:
ISourceCodePosition() {}
ISourceCodePosition() = default;
ISourceCodePosition(const ISourceCodePosition &src) = default;
int GetLineNumber() const { return _start.Line(); }
int GetColumnNumber() const { return _start.Column(); }
Expand Down Expand Up @@ -113,38 +113,32 @@ class CompileResult
_resourceType = ResourceType::None;
}

CompileResult(const std::string &message, CompileResultType type = CRT_Message)
CompileResult(const std::string &message, CompileResultType type = CRT_Message) : _message(message)
{
_message = message;
_nLine = 0;
_nCol = 0;
_type = type;
_resourceType = ResourceType::None;
}

// For other resources.
CompileResult(const std::string &message, ResourceType type, int number, int index)
CompileResult(const std::string &message, ResourceType type, int number, int index) : _message(message)
{
_message = message;
_nLine = number;
_nCol = index;
_type = CRT_Message;
_resourceType = type;
}

CompileResult(const std::string &message, ScriptId script, int nLineNumber)
CompileResult(const std::string &message, ScriptId script, int nLineNumber) : _message(message), _script(script)
{
_message = message;
_script = script;
_nLine = nLineNumber;
_nCol = 0;
_type = CRT_Message;
_resourceType = ResourceType::None;
}
CompileResult(const std::string &message, ScriptId script, int nLineNumber, int nCol, CompileResultType type)
CompileResult(const std::string &message, ScriptId script, int nLineNumber, int nCol, CompileResultType type) : _message(message), _script(script)
{
_message = message;
_script = script;
_nLine = nLineNumber;
_nCol = nCol;
_type = type;
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/CrystalEdit/CCrystalTextBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enum LINEFLAGS
LF_INVALID_BREAKPOINT = 0x00100000L
};

#define LF_BOOKMARK(id) (LF_BOOKMARK_FIRST << id)
#define LF_BOOKMARK(id) (LF_BOOKMARK_FIRST << (id))

enum CRLFSTYLE
{
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Dialogs/PicClipsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct sRECT;

struct PicClip
{
PicClip() {}
PicClip() = default;
PicClip(const std::string &name, const sRECT &bounds, std::unique_ptr<std::vector<PicCommand>> &&Commands);


Expand Down
5 changes: 1 addition & 4 deletions SCICompanionLib/Src/MFCDocuments/ResourceEntityDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ class ResourceEntityDocument : public CUndoResource<CResourceDocument, ResourceE
// Go ahead and notify things...
UpdateAllViewsAndNonViews(nullptr, 0, &updateHint);

if (modified)
{
SetModifiedFlag(TRUE);
}
SetModifiedFlag(TRUE);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/MFCViews/ScrollingThing.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void CScrollingThing<T>::_OnScroll(int iType, UINT nSBCode, UINT nPos)
case SB_LINEDOWN: _ScrollDelta(iType, hwnd, +1); break;
case SB_PAGEUP: _ScrollDelta(iType, hwnd, -iPageDelta); break;
case SB_PAGEDOWN: _ScrollDelta(iType, hwnd, +iPageDelta); break;
case SB_THUMBPOSITION: _ScrollTo(iType, hwnd, nPos); break;
case SB_THUMBPOSITION: //...same as...
case SB_THUMBTRACK: _ScrollTo(iType, hwnd, nPos); break;
case SB_TOP: _ScrollTo(iType, hwnd, 0); break;
case SB_BOTTOM: _ScrollTo(iType, hwnd, MAXLONG); break;
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Resources/GameFolderHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class ResourceSaveLocation : uint16_t
class GameFolderHelper
{
public:
GameFolderHelper() {}
GameFolderHelper() = default;
GameFolderHelper(const GameFolderHelper &orig) = default;
GameFolderHelper &operator=(const GameFolderHelper &other) = default;

Expand Down
4 changes: 4 additions & 0 deletions SCICompanionLib/Src/Resources/Pic.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ TPoint GameResolutionToScreenResolution(TPoint point, NativeResolution resolutio
{
switch (resolution)
{
case NativeResolution::Res320x200:
break;
case NativeResolution::Res640x400:
point.x *= 2;
point.y *= 2;
Expand All @@ -73,6 +75,8 @@ TPoint ScreenResolutionToGameResolution(TPoint point, NativeResolution resolutio
{
switch (resolution)
{
case NativeResolution::Res320x200:
break;
case NativeResolution::Res640x400:
point.x /= 2;
point.y /= 2;
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Resources/PicCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace sci
// fwd decl
class ResourceEntity;

#define BUFFEROFFSET_NONSTD(cx, cy, x, y) (((cy) - 1) -(y))*cx+(x)
#define BUFFEROFFSET_NONSTD(cx, cy, x, y) (((cy) - 1) -(y))*(cx)+(x)

// Pic opcodes
const uint8_t PIC_OP_SET_COLOR = 0xf0;
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Resources/RasterOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ DEFINE_ENUM_FLAGS(RasterChangeHint, uint32_t)

struct RasterChange
{
RasterChange() {}
RasterChange() = default;
RasterChange(RasterChangeHint hint, CelIndex index) : hint(hint), index(index) {}
RasterChange(RasterChangeHint hint) : hint(hint) {}
RasterChange(const RasterChange &src) = default;
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Resources/ResourceBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct RESOURCEHEADER_SCI0

ResourceType GetType() { return (ResourceType)iType; }

ResourceHeaderAgnostic ToAgnostic(SCIVersion version, ResourceSourceFlags sourceFlags, uint16_t packageHint)
ResourceHeaderAgnostic ToAgnostic(const SCIVersion &version, ResourceSourceFlags sourceFlags, uint16_t packageHint)
{
ResourceHeaderAgnostic agnostic;
agnostic.Type = GetType();
Expand Down
4 changes: 1 addition & 3 deletions SCICompanionLib/Src/Resources/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ extern uint8_t g_vgaPaletteMapping[256];

struct Cel
{
Cel(size16 size, point16 placement, uint8_t transparentColor)
Cel(size16 size, point16 placement, uint8_t transparentColor) : size(size), placement(placement)
{
this->size = size;
this->placement = placement;
this->TransparentColor = transparentColor;
this->Stride32 = true;
}
Expand Down
4 changes: 2 additions & 2 deletions SCICompanionLib/Src/Util/CodeAutoComplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class AutoCompleteResult
{
public:
AutoCompleteResult() { Reset(); }
~AutoCompleteResult() {}
void Add(PCTSTR psz, AutoCompleteIconIndex iIcon) { choices.push_back(AutoCompleteChoice(psz, iIcon)); }
~AutoCompleteResult() = default;
void Add(PCTSTR psz, AutoCompleteIconIndex iIcon) { choices.emplace_back(AutoCompleteChoice(psz, iIcon)); }
void AddOnFirstLetter(PCTSTR pszLetters, PCTSTR pszText, AutoCompleteIconIndex iIcon)
{
fACType = pszLetters[0] ? AC_ShowOnFirst_Shown : AC_ShowOnFirst_Empty;
Expand Down
4 changes: 1 addition & 3 deletions SCICompanionLib/Src/Util/CrystalScriptStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class CScriptStreamLimiter
CScriptStreamLimiter(CCrystalTextBuffer *pBuffer);
CScriptStreamLimiter(CCrystalTextBuffer *pBuffer, CPoint ptLimit, int extraSpace);

~CScriptStreamLimiter()
{
}
~CScriptStreamLimiter() = default;

void Extend(const std::string &extraChars) { _pBuffer->Extend(extraChars); }

Expand Down
3 changes: 2 additions & 1 deletion SCICompanionLib/Src/Util/QueueItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class QueueItems : public std::enable_shared_from_this<QueueItems<TITEM, TRESULT
_thread.detach();
fRet = true;
}
catch (std::system_error)
catch (std::system_error&)
{
assert(false);
}
return fRet;
}
Expand Down
2 changes: 2 additions & 0 deletions SCICompanionLib/Src/Util/StlUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ namespace sci

array &operator=(const array &src)
{
if (this == std::addressof(src))
return *this;
delete[] _data;
_allocateInternal(src._size);
if (_size > 0)
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Util/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace sci
return *this;
}

ostream &operator<< (const std::string aString)
ostream &operator<< (const std::string &aString)
{
WriteBytes(reinterpret_cast<const uint8_t*>(aString.c_str()), (int)aString.length() + 1);
return *this;
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Util/TalkerToViewMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AppState;
class TalkerToViewMap
{
public:
TalkerToViewMap() {}
TalkerToViewMap() = default;
TalkerToViewMap(const std::string &talker);
bool TalkerToViewLoop(uint16_t talker, uint16_t &view, uint16_t &loop) const;
void SetTalkerToViewLoop(uint16_t talker, uint16_t view, uint16_t loop);
Expand Down
2 changes: 1 addition & 1 deletion SCICompanionLib/Src/Util/sci.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ EGACOLOR GetClosestEGAColorFromSet(int iAlgorithm, bool gammaCorrected, COLORREF
//
struct SCIBitmapInfo : public BITMAPINFO
{
SCIBitmapInfo() {}
SCIBitmapInfo() = default;
SCIBitmapInfo(int cx, int cy, const RGBQUAD *pPalette = nullptr, int count = 0);
RGBQUAD _colors[256];
};
Expand Down

0 comments on commit 33f756f

Please sign in to comment.