From 5fe6801b1b2b652be8bd3244cfc6ae90b7466f16 Mon Sep 17 00:00:00 2001 From: Kissaki Date: Mon, 3 Oct 2011 14:46:48 +0200 Subject: [PATCH] handle some cppcheck-found issues: * uninitialized membervars, * AudioOutput.cpp: fix delete on array to delete[] * OSS.cpp: close file descriptor in false data case * OverlayEditorScene.cpp: rm duplicate logic * fix ifndef to match usage of declared variable * member var initializations * check for null (ds in d3d9 as some lines above), * lower scope of var decl., * swap bufsize check and array dereference so check is before! deref, * initialize member vars in constr. --- overlay/HardHook.cpp | 2 +- overlay/d3d9.cpp | 3 ++- overlay/lib.cpp | 6 +++--- src/mumble/ASIOInput.cpp | 6 +++--- src/mumble/AudioOutput.cpp | 6 +++--- src/mumble/CoreAudio.cpp | 1 + src/mumble/DirectSound.cpp | 1 + src/mumble/G15LCDEngine_helper.cpp | 2 +- src/mumble/G15LCDEngine_lglcd.cpp | 2 +- src/mumble/Global.cpp | 1 + src/mumble/GlobalShortcut_unix.cpp | 3 ++- src/mumble/OSS.cpp | 2 ++ src/mumble/OverlayEditorScene.cpp | 2 -- src/mumble/OverlayText.cpp | 20 +++++++++++++++----- src/mumble/ServerHandler.cpp | 4 ++++ src/mumble/WASAPI.cpp | 1 + src/murmur/DBus.cpp | 2 +- src/murmur/DBus.h | 12 ++++++------ src/murmur/ServerUser.cpp | 2 +- src/murmur/UnixMurmur.cpp | 2 +- src/murmur/main.cpp | 2 +- 21 files changed, 51 insertions(+), 31 deletions(-) diff --git a/overlay/HardHook.cpp b/overlay/HardHook.cpp index e41810ce4dd..652bb18f9c3 100644 --- a/overlay/HardHook.cpp +++ b/overlay/HardHook.cpp @@ -34,7 +34,7 @@ void *HardHook::pCode = NULL; unsigned int HardHook::uiCode = 0; -HardHook::HardHook() { +HardHook::HardHook() : bTrampoline(false), call(0) { int i; baseptr = NULL; for (i=0;i<6;i++) diff --git a/overlay/d3d9.cpp b/overlay/d3d9.cpp index cf8b2ecdf12..b2b1195a9c6 100644 --- a/overlay/d3d9.cpp +++ b/overlay/d3d9.cpp @@ -414,7 +414,8 @@ static HRESULT __stdcall myReset(IDirect3DDevice9 * idd, D3DPRESENT_PARAMETERS * HRESULT hr=oReset(idd, param); hhReset.inject(); - ds->createCleanState(); + if (ds) + ds->createCleanState(); return hr; } diff --git a/overlay/lib.cpp b/overlay/lib.cpp index 351c5704883..a10d27cc754 100644 --- a/overlay/lib.cpp +++ b/overlay/lib.cpp @@ -493,7 +493,6 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { bBlackListed = TRUE; bMumble = TRUE; } else { - int i = 0; DWORD buffsize = MAX_PATH * 20; // Initial buffer size for registry operation bool usewhitelist; @@ -531,7 +530,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { if (usewhitelist) { bool onwhitelist = false; - while (buffer[pos] != 0 && pos < buffsize) { + while (pos < buffsize && buffer[pos] != 0) { if (_stricmp(procname, buffer + pos) == 0 || _stricmp(p+1, buffer + pos) == 0) { fods("Overlay enabled for whitelisted '%s'", buffer + pos); onwhitelist = true; @@ -546,7 +545,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { break; } } else { - while (buffer[pos] != 0 && pos < buffsize) { + while (pos < buffsize && buffer[pos] != 0) { if (_stricmp(procname, buffer + pos) == 0 || _stricmp(p+1, buffer + pos) == 0) { fods("Overlay blacklist entry found for '%s'", buffer + pos); bBlackListed = TRUE; @@ -558,6 +557,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { } else { // If there is no list in the registry fallback to using the default blacklist fods("Overlay fallback to default blacklist"); + int i = 0; while (overlayBlacklist[i]) { if (_stricmp(procname, overlayBlacklist[i]) == 0 || _stricmp(p+1, overlayBlacklist[i])==0) { fods("Overlay default blacklist entry found for '%s'", overlayBlacklist[i]); diff --git a/src/mumble/ASIOInput.cpp b/src/mumble/ASIOInput.cpp index 231535b2e2f..5cdb6d55c47 100644 --- a/src/mumble/ASIOInput.cpp +++ b/src/mumble/ASIOInput.cpp @@ -68,6 +68,7 @@ class ASIOInit : public DeferInit { ASIOAudioInputRegistrar *airASIO; ConfigRegistrar *crASIO; public: + ASIOInit() : airASIO(NULL), crASIO(NULL) {} void initialize(); void destroy(); }; @@ -403,8 +404,6 @@ ASIOInput::ASIOInput() { abiInfo = NULL; aciInfo = NULL; - int i, idx; - // Sanity check things first. iNumMic=g.s.qlASIOmic.count(); @@ -465,7 +464,8 @@ ASIOInput::ASIOInput() { abiInfo = new ASIOBufferInfo[iNumMic + iNumSpeaker]; aciInfo = new ASIOChannelInfo[iNumMic + iNumSpeaker]; - idx = 0; + + int i, idx = 0; for (i=0;i G15LCDEngineLGLCD::devices() const { /* -- */ -G15LCDDeviceLGLCD::G15LCDDeviceLGLCD(G15LCDEngineLGLCD *e) : LCDDevice() { +G15LCDDeviceLGLCD::G15LCDDeviceLGLCD(G15LCDEngineLGLCD *e) : LCDDevice(), bEnabled(false) { engine = e; } diff --git a/src/mumble/Global.cpp b/src/mumble/Global.cpp index 61f27a422ad..6b28abea27a 100644 --- a/src/mumble/Global.cpp +++ b/src/mumble/Global.cpp @@ -73,6 +73,7 @@ Global::Global() { bPosTest = false; bInAudioWizard = false; iAudioPathTime = 0; + iAudioBandwidth = -1; iMaxBandwidth = -1; iCodecAlpha = 0; diff --git a/src/mumble/GlobalShortcut_unix.cpp b/src/mumble/GlobalShortcut_unix.cpp index 48b0442c8ed..ebbb816c6d7 100644 --- a/src/mumble/GlobalShortcut_unix.cpp +++ b/src/mumble/GlobalShortcut_unix.cpp @@ -35,7 +35,8 @@ GlobalShortcutEngine *GlobalShortcutEngine::platformInit() { } GlobalShortcutX::GlobalShortcutX() { - bRunning=false; + iXIopcode = -1; + bRunning = false; display = NULL; diff --git a/src/mumble/OSS.cpp b/src/mumble/OSS.cpp index 1aca70e62c1..aae1615cb35 100644 --- a/src/mumble/OSS.cpp +++ b/src/mumble/OSS.cpp @@ -297,6 +297,8 @@ void OSSOutput::run() { ival = AFMT_S16_NE; if ((ioctl(fd, SNDCTL_DSP_SETFMT, &ival) == -1) || (ival != AFMT_S16_NE)) { qWarning("OSSOutput: Failed to set sound format"); + if ((ival != AFMT_S16_NE)) + close(fd); return; } diff --git a/src/mumble/OverlayEditorScene.cpp b/src/mumble/OverlayEditorScene.cpp index 45d7f4f883a..a0b7d72ae13 100644 --- a/src/mumble/OverlayEditorScene.cpp +++ b/src/mumble/OverlayEditorScene.cpp @@ -197,8 +197,6 @@ void OverlayEditorScene::updateSelected() { updateAvatar(); else if (qgpiSelected == qgpiName) updateUserName(); - else if (qgpiSelected == qgpiAvatar) - updateAvatar(); else if (qgpiSelected == qgpiMuted) updateMuted(); } diff --git a/src/mumble/OverlayText.cpp b/src/mumble/OverlayText.cpp index 4dc14aed3d5..3d4e8ebdccf 100644 --- a/src/mumble/OverlayText.cpp +++ b/src/mumble/OverlayText.cpp @@ -32,19 +32,27 @@ #include "Global.h" BasepointPixmap::BasepointPixmap() : - qpBasePoint(0, 0) { } + qpBasePoint(0, 0), + iAscent(-1), + iDescent(-1) { } BasepointPixmap::BasepointPixmap(const QPixmap& pm) : QPixmap(pm), - qpBasePoint(0, pm.height()) { } + qpBasePoint(0, pm.height()), + iAscent(-1), + iDescent(-1) { } BasepointPixmap::BasepointPixmap(int w, int h) : QPixmap(w, h), - qpBasePoint(0, h) { } + qpBasePoint(0, h), + iAscent(-1), + iDescent(-1) { } BasepointPixmap::BasepointPixmap(int w, int h, const QPoint& bp) : QPixmap(w, h), - qpBasePoint(bp) { } + qpBasePoint(bp), + iAscent(-1), + iDescent(-1) { } OverlayTextLine::OverlayTextLine(const QString& s, const QFont& f) : fEdgeFactor(0.05f), @@ -53,7 +61,9 @@ OverlayTextLine::OverlayTextLine(const QString& s, const QFont& f) : iCurWidth(-1), iCurHeight(-1), fBaseliningThreshold(0.5f), - bElided(false) { + bElided(false), + fXCorrection(0.0), + fYCorrection(0.0) { QFontMetrics fm(f); fAscent = static_cast(fm.ascent()); fDescent = static_cast(fm.descent()); diff --git a/src/mumble/ServerHandler.cpp b/src/mumble/ServerHandler.cpp index 1f4ec298396..4fa8e447eab 100644 --- a/src/mumble/ServerHandler.cpp +++ b/src/mumble/ServerHandler.cpp @@ -85,6 +85,10 @@ ServerHandler::ServerHandler() { cConnection.reset(); qusUdp = NULL; bStrong = false; + usPort = 0; + bUdp = true; + tConnectionTimeoutTimer = NULL; + uiVersion = 0; // For some strange reason, on Win32, we have to call supportsSsl before the cipher list is ready. qWarning("OpenSSL Support: %d (%s)", QSslSocket::supportsSsl(), SSLeay_version(SSLEAY_VERSION)); diff --git a/src/mumble/WASAPI.cpp b/src/mumble/WASAPI.cpp index 21ad99725dd..cdacb7eda01 100644 --- a/src/mumble/WASAPI.cpp +++ b/src/mumble/WASAPI.cpp @@ -72,6 +72,7 @@ class WASAPIInit : public DeferInit { WASAPIInputRegistrar *wirReg; WASAPIOutputRegistrar *worReg; public: + WASAPIInit() : wirReg(NULL), worReg(NULL) { } void initialize(); void destroy(); }; diff --git a/src/murmur/DBus.cpp b/src/murmur/DBus.cpp index 8f6822e664a..20addfdb30c 100644 --- a/src/murmur/DBus.cpp +++ b/src/murmur/DBus.cpp @@ -738,7 +738,7 @@ ACLInfo::ACLInfo(const ChanACL *acl) { deny = acl->pDeny; } -GroupInfo::GroupInfo(const Group *g) { +GroupInfo::GroupInfo(const Group *g) : inherited(false) { name = g->qsName; inherit = g->bInherit; inheritable = g->bInheritable; diff --git a/src/murmur/DBus.h b/src/murmur/DBus.h index 98046ebc1f5..9a3e8e6df74 100644 --- a/src/murmur/DBus.h +++ b/src/murmur/DBus.h @@ -49,7 +49,7 @@ struct PlayerInfo { bool mute, deaf, suppressed; bool selfMute, selfDeaf; int channel; - PlayerInfo() { }; + PlayerInfo() : session(0), mute(false), deaf(false), suppressed(false), selfMute(false), selfDeaf(false), channel(-1) { }; PlayerInfo(const User *); }; Q_DECLARE_METATYPE(PlayerInfo); @@ -59,7 +59,7 @@ struct PlayerInfoExtended : public PlayerInfo { QString name; int onlinesecs; int bytespersec; - PlayerInfoExtended() {}; + PlayerInfoExtended() : id(-1), onlinesecs(-1), bytespersec(-1) {}; PlayerInfoExtended(const User *); }; Q_DECLARE_METATYPE(PlayerInfoExtended); @@ -70,7 +70,7 @@ struct ChannelInfo { QString name; int parent; QList links; - ChannelInfo() { }; + ChannelInfo() : id(-1), parent(-1) { }; ChannelInfo(const Channel *c); }; Q_DECLARE_METATYPE(ChannelInfo); @@ -80,7 +80,7 @@ struct GroupInfo { QString name; bool inherited, inherit, inheritable; QList add, remove, members; - GroupInfo() { }; + GroupInfo() : inherited(false), inherit(false), inheritable(false) { }; GroupInfo(const Group *g); }; Q_DECLARE_METATYPE(GroupInfo); @@ -91,7 +91,7 @@ struct ACLInfo { int playerid; QString group; unsigned int allow, deny; - ACLInfo() { }; + ACLInfo() : applyHere(false), applySubs(false), inherited(false) { }; ACLInfo(const ChanACL *acl); }; Q_DECLARE_METATYPE(ACLInfo); @@ -100,7 +100,7 @@ Q_DECLARE_METATYPE(QList); struct BanInfo { unsigned int address; int bits; - BanInfo() { }; + BanInfo() : address(0), bits(0) { }; BanInfo(const Ban &); }; Q_DECLARE_METATYPE(BanInfo); diff --git a/src/murmur/ServerUser.cpp b/src/murmur/ServerUser.cpp index aacee597b16..3af2be76a32 100644 --- a/src/murmur/ServerUser.cpp +++ b/src/murmur/ServerUser.cpp @@ -35,7 +35,7 @@ #include "ServerUser.h" #include "Meta.h" -ServerUser::ServerUser(Server *p, QSslSocket *socket) : Connection(p, socket), User() { +ServerUser::ServerUser(Server *p, QSslSocket *socket) : Connection(p, socket), User(), s(NULL) { sState = ServerUser::Connected; sUdpSocket = INVALID_SOCKET; diff --git a/src/murmur/UnixMurmur.cpp b/src/murmur/UnixMurmur.cpp index 9e1c81c08e6..13b067ea654 100644 --- a/src/murmur/UnixMurmur.cpp +++ b/src/murmur/UnixMurmur.cpp @@ -36,7 +36,7 @@ QMutex *LimitTest::qm; QWaitCondition *LimitTest::qw; QWaitCondition *LimitTest::qstartw; -LimitTest::LimitTest() : QThread() { +LimitTest::LimitTest() : QThread(), tid(-1) { } void LimitTest::run() { diff --git a/src/murmur/main.cpp b/src/murmur/main.cpp index b29d10c05e1..f70cc2ca103 100644 --- a/src/murmur/main.cpp +++ b/src/murmur/main.cpp @@ -196,7 +196,7 @@ int main(int argc, char **argv) { bool wipeSsl = false; bool wipeLogs = false; int sunum = 1; -#ifndef Q_OS_WIN +#ifdef Q_OS_UNIX bool readPw = false; #endif