Skip to content

Commit

Permalink
handle some cppcheck-found issues:
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Kissaki committed Oct 9, 2011
1 parent 683d39b commit 5fe6801
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion overlay/HardHook.cpp
Expand Up @@ -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++)
Expand Down
3 changes: 2 additions & 1 deletion overlay/d3d9.cpp
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions overlay/lib.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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]);
Expand Down
6 changes: 3 additions & 3 deletions src/mumble/ASIOInput.cpp
Expand Up @@ -68,6 +68,7 @@ class ASIOInit : public DeferInit {
ASIOAudioInputRegistrar *airASIO;
ConfigRegistrar *crASIO;
public:
ASIOInit() : airASIO(NULL), crASIO(NULL) {}
void initialize();
void destroy();
};
Expand Down Expand Up @@ -403,8 +404,6 @@ ASIOInput::ASIOInput() {
abiInfo = NULL;
aciInfo = NULL;

int i, idx;

// Sanity check things first.

iNumMic=g.s.qlASIOmic.count();
Expand Down Expand Up @@ -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<iNumMic;i++) {
abiInfo[idx].isInput = true;
abiInfo[idx].channelNum = g.s.qlASIOmic[i].toInt();
Expand Down
6 changes: 3 additions & 3 deletions src/mumble/AudioOutput.cpp
Expand Up @@ -849,9 +849,9 @@ void AudioOutput::removeBuffer(AudioOutputUser *aop) {
}

void AudioOutput::initializeMixer(const unsigned int *chanmasks, bool forceheadphone) {
delete fSpeakers;
delete bSpeakerPositional;
delete fSpeakerVolume;
delete[] fSpeakers;
delete[] bSpeakerPositional;
delete[] fSpeakerVolume;

fSpeakers = new float[iChannels * 3];
bSpeakerPositional = new bool[iChannels];
Expand Down
1 change: 1 addition & 0 deletions src/mumble/CoreAudio.cpp
Expand Up @@ -55,6 +55,7 @@ class CoreAudioInit : public DeferInit {
CoreAudioInputRegistrar *cairReg;
CoreAudioOutputRegistrar *caorReg;
public:
CoreAudioInit() : cairReg(NULL), caorReg(NULL) {}
void initialize();
void destroy();
};
Expand Down
1 change: 1 addition & 0 deletions src/mumble/DirectSound.cpp
Expand Up @@ -65,6 +65,7 @@ class DirectSoundInit : public DeferInit {
DXAudioInputRegistrar *airReg;
DXAudioOutputRegistrar *aorReg;
public:
DirectSoundInit() : airReg(NULL), aorReg(NULL) {}
void initialize();
void destroy();
};
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/G15LCDEngine_helper.cpp
Expand Up @@ -121,7 +121,7 @@ void G15LCDEngineHelper::submitFrame(bool alert, unsigned char *buf, size_t len)

/* -- */

G15LCDDeviceHelper::G15LCDDeviceHelper(G15LCDEngineHelper *e) : LCDDevice() {
G15LCDDeviceHelper::G15LCDDeviceHelper(G15LCDEngineHelper *e) : LCDDevice(), bEnabled(false) {
engine = e;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mumble/G15LCDEngine_lglcd.cpp
Expand Up @@ -99,7 +99,7 @@ QList<LCDDevice *> G15LCDEngineLGLCD::devices() const {

/* -- */

G15LCDDeviceLGLCD::G15LCDDeviceLGLCD(G15LCDEngineLGLCD *e) : LCDDevice() {
G15LCDDeviceLGLCD::G15LCDDeviceLGLCD(G15LCDEngineLGLCD *e) : LCDDevice(), bEnabled(false) {
engine = e;
}

Expand Down
1 change: 1 addition & 0 deletions src/mumble/Global.cpp
Expand Up @@ -73,6 +73,7 @@ Global::Global() {
bPosTest = false;
bInAudioWizard = false;
iAudioPathTime = 0;
iAudioBandwidth = -1;
iMaxBandwidth = -1;

iCodecAlpha = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/mumble/GlobalShortcut_unix.cpp
Expand Up @@ -35,7 +35,8 @@ GlobalShortcutEngine *GlobalShortcutEngine::platformInit() {
}

GlobalShortcutX::GlobalShortcutX() {
bRunning=false;
iXIopcode = -1;
bRunning = false;

display = NULL;

Expand Down
2 changes: 2 additions & 0 deletions src/mumble/OSS.cpp
Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions src/mumble/OverlayEditorScene.cpp
Expand Up @@ -197,8 +197,6 @@ void OverlayEditorScene::updateSelected() {
updateAvatar();
else if (qgpiSelected == qgpiName)
updateUserName();
else if (qgpiSelected == qgpiAvatar)
updateAvatar();
else if (qgpiSelected == qgpiMuted)
updateMuted();
}
Expand Down
20 changes: 15 additions & 5 deletions src/mumble/OverlayText.cpp
Expand Up @@ -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),
Expand All @@ -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<float>(fm.ascent());
fDescent = static_cast<float>(fm.descent());
Expand Down
4 changes: 4 additions & 0 deletions src/mumble/ServerHandler.cpp
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/mumble/WASAPI.cpp
Expand Up @@ -72,6 +72,7 @@ class WASAPIInit : public DeferInit {
WASAPIInputRegistrar *wirReg;
WASAPIOutputRegistrar *worReg;
public:
WASAPIInit() : wirReg(NULL), worReg(NULL) { }
void initialize();
void destroy();
};
Expand Down
2 changes: 1 addition & 1 deletion src/murmur/DBus.cpp
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/murmur/DBus.h
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -70,7 +70,7 @@ struct ChannelInfo {
QString name;
int parent;
QList<int> links;
ChannelInfo() { };
ChannelInfo() : id(-1), parent(-1) { };
ChannelInfo(const Channel *c);
};
Q_DECLARE_METATYPE(ChannelInfo);
Expand All @@ -80,7 +80,7 @@ struct GroupInfo {
QString name;
bool inherited, inherit, inheritable;
QList<int> add, remove, members;
GroupInfo() { };
GroupInfo() : inherited(false), inherit(false), inheritable(false) { };
GroupInfo(const Group *g);
};
Q_DECLARE_METATYPE(GroupInfo);
Expand All @@ -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);
Expand All @@ -100,7 +100,7 @@ Q_DECLARE_METATYPE(QList<ACLInfo>);
struct BanInfo {
unsigned int address;
int bits;
BanInfo() { };
BanInfo() : address(0), bits(0) { };
BanInfo(const Ban &);
};
Q_DECLARE_METATYPE(BanInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/murmur/ServerUser.cpp
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/murmur/UnixMurmur.cpp
Expand Up @@ -36,7 +36,7 @@ QMutex *LimitTest::qm;
QWaitCondition *LimitTest::qw;
QWaitCondition *LimitTest::qstartw;

LimitTest::LimitTest() : QThread() {
LimitTest::LimitTest() : QThread(), tid(-1) {
}

void LimitTest::run() {
Expand Down
2 changes: 1 addition & 1 deletion src/murmur/main.cpp
Expand Up @@ -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

Expand Down

0 comments on commit 5fe6801

Please sign in to comment.