Skip to content

Commit

Permalink
Merge pull request deskflow#6045 from symless/v1.9-pvs-studio
Browse files Browse the repository at this point in the history
PVS Studio related bugfixes for v1.9
  • Loading branch information
nlyan authored May 22, 2017
2 parents 56f7403 + 98e617a commit 0953ac0
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 63 deletions.
1 change: 1 addition & 0 deletions src/gui/src/DataDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

DataDownloader::DataDownloader(QObject* parent) :
QObject(parent),
m_pReply(nullptr),
m_IsFinished(false)
{
connect(&m_NetworkManager, SIGNAL(finished(QNetworkReply*)),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/ScreenSetupView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ScreenSetupView::ScreenSetupView(QWidget* parent) :
verticalHeader()->hide();
}

void ScreenSetupView::setModel(ScreenSetupModel* model)
void ScreenSetupView::setModel(QAbstractItemModel* model)
{
QTableView::setModel(model);
setTableSize();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/ScreenSetupView.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ScreenSetupView : public QTableView
ScreenSetupView(QWidget* parent);

public:
void setModel(ScreenSetupModel* model);
void setModel(QAbstractItemModel* model) override;
ScreenSetupModel* model() const;

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/ZeroconfServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ZeroconfServer::ZeroconfServer(QObject* parent) :
{
}

void ZeroconfServer::incomingConnection(int socketDescriptor)
void ZeroconfServer::incomingConnection(qintptr socketDescriptor)
{
ZeroconfThread* thread = new ZeroconfThread(socketDescriptor, this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/ZeroconfServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ZeroconfServer : public QTcpServer
ZeroconfServer(QObject* parent = 0);

protected:
void incomingConnection(int socketDescriptor);
void incomingConnection(qintptr socketDescriptor) override;

private:
QStringList fortunes;
Expand Down
20 changes: 10 additions & 10 deletions src/lib/arch/IArchString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int
IArchString::convStringWCToMB(char* dst,
const wchar_t* src, UInt32 n, bool* errors)
{
int len = 0;
ptrdiff_t len = 0;

bool dummyErrors;
if (errors == NULL) {
Expand All @@ -58,22 +58,22 @@ IArchString::convStringWCToMB(char* dst,
if (dst == NULL) {
char dummy[MB_LEN_MAX];
for (const wchar_t* scan = src; n > 0; ++scan, --n) {
int mblen = wctomb(dummy, *scan);
ptrdiff_t mblen = wctomb(dummy, *scan);
if (mblen == -1) {
*errors = true;
mblen = 1;
}
len += mblen;
}
int mblen = wctomb(dummy, L'\0');
ptrdiff_t mblen = wctomb(dummy, L'\0');
if (mblen != -1) {
len += mblen - 1;
}
}
else {
char* dst0 = dst;
for (const wchar_t* scan = src; n > 0; ++scan, --n) {
int mblen = wctomb(dst, *scan);
ptrdiff_t mblen = wctomb(dst, *scan);
if (mblen == -1) {
*errors = true;
*dst++ = '?';
Expand All @@ -82,12 +82,12 @@ IArchString::convStringWCToMB(char* dst,
dst += mblen;
}
}
int mblen = wctomb(dst, L'\0');
ptrdiff_t mblen = wctomb(dst, L'\0');
if (mblen != -1) {
// don't include nul terminator
dst += mblen - 1;
}
len = (int)(dst - dst0);
len = dst - dst0;
}
ARCH->unlockMutex(s_mutex);

Expand All @@ -98,7 +98,7 @@ int
IArchString::convStringMBToWC(wchar_t* dst,
const char* src, UInt32 n, bool* errors)
{
int len = 0;
ptrdiff_t len = 0;
wchar_t dummy;

bool dummyErrors;
Expand All @@ -114,7 +114,7 @@ IArchString::convStringMBToWC(wchar_t* dst,

if (dst == NULL) {
for (const char* scan = src; n > 0; ) {
int mblen = mbtowc(&dummy, scan, n);
ptrdiff_t mblen = mbtowc(&dummy, scan, n);
switch (mblen) {
case -2:
// incomplete last character. convert to unknown character.
Expand Down Expand Up @@ -150,7 +150,7 @@ IArchString::convStringMBToWC(wchar_t* dst,
else {
wchar_t* dst0 = dst;
for (const char* scan = src; n > 0; ++dst) {
int mblen = mbtowc(dst, scan, n);
ptrdiff_t mblen = mbtowc(dst, scan, n);
switch (mblen) {
case -2:
// incomplete character. convert to unknown character.
Expand Down Expand Up @@ -181,7 +181,7 @@ IArchString::convStringMBToWC(wchar_t* dst,
break;
}
}
len = (int)(dst - dst0);
len = dst - dst0;
}
ARCH->unlockMutex(s_mutex);

Expand Down
10 changes: 7 additions & 3 deletions src/lib/arch/win32/ArchNetworkWinsock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ ArchNetworkWinsock::listenOnSocket(ArchSocket s)
}

ArchSocket
ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress* addr)
ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress* const addr)
{
assert(s != NULL);

Expand All @@ -325,7 +325,9 @@ ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress* addr)
int err = getsockerror_winsock();
delete socket;
free(tmp);
*addr = NULL;
if (addr) {
*addr = NULL;
}
if (err == WSAEWOULDBLOCK) {
return NULL;
}
Expand All @@ -339,7 +341,9 @@ ArchNetworkWinsock::acceptSocket(ArchSocket s, ArchNetAddress* addr)
close_winsock(fd);
delete socket;
free(tmp);
*addr = NULL;
if (addr) {
*addr = NULL;
}
throw;
}

Expand Down
10 changes: 7 additions & 3 deletions src/lib/arch/win32/ArchTaskBarWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ static const UINT kFirstReceiverID = WM_USER + 14;
ArchTaskBarWindows* ArchTaskBarWindows::s_instance = NULL;

ArchTaskBarWindows::ArchTaskBarWindows() :
m_nextID(kFirstReceiverID),
m_thread(NULL),
m_mutex(NULL),
m_condVar(NULL),
m_mutex(NULL)
m_ready(false),
m_result(0),
m_thread(NULL),
m_hwnd(NULL),
m_taskBarRestart(0),
m_nextID(kFirstReceiverID)
{
// save the singleton instance
s_instance = this;
Expand Down
18 changes: 10 additions & 8 deletions src/lib/base/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cerrno>

namespace synergy {
namespace string {
Expand All @@ -50,8 +51,8 @@ vformat(const char* fmt, va_list args)
// find highest indexed substitution and the locations of substitutions
std::vector<size_t> pos;
std::vector<size_t> width;
std::vector<int> index;
int maxIndex = 0;
std::vector<size_t> index;
size_t maxIndex = 0;
for (const char* scan = fmt; *scan != '\0'; ++scan) {
if (*scan == '%') {
++scan;
Expand All @@ -61,21 +62,22 @@ vformat(const char* fmt, va_list args)
else if (*scan == '%') {
// literal
index.push_back(0);
pos.push_back(static_cast<int>(scan - 1 - fmt));
pos.push_back(static_cast<size_t>((scan - 1) - fmt));
width.push_back(2);
}
else if (*scan == '{') {
// get argument index
char* end;
int i = static_cast<int>(strtol(scan + 1, &end, 10));
if (*end != '}') {
errno = 0;
long i = strtol(scan + 1, &end, 10);
if (errno || (i < 0) || (*end != '}')) {
// invalid index -- ignore
scan = end - 1;
scan = end - 1; // BUG if there are digits?
}
else {
index.push_back(i);
pos.push_back(static_cast<int>(scan - 1 - fmt));
width.push_back(static_cast<int>(end - scan + 2));
pos.push_back(static_cast<size_t>((scan - 1) - fmt));
width.push_back(static_cast<size_t>((end - scan) + 2));
if (i > maxIndex) {
maxIndex = i;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/ipc/IpcLogOutputter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ IpcLogOutputter::IpcLogOutputter(IpcServer& ipcServer, EIpcClientType clientType
m_running(false),
m_notifyCond(ARCH->newCondVar()),
m_notifyMutex(ARCH->newMutex()),
m_bufferThreadId(0),
m_bufferWaiting(false),
m_bufferMaxSize(kBufferMaxSize),
m_bufferRateWriteLimit(kBufferRateWriteLimit),
Expand Down
1 change: 0 additions & 1 deletion src/lib/ipc/IpcLogOutputter.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class IpcLogOutputter : public ILogOutputter {
double m_bufferRateTimeLimit;
UInt16 m_bufferWriteCount;
double m_bufferRateStart;
bool m_useThread;
EIpcClientType m_clientType;
ArchMutex m_runningMutex;
};
2 changes: 1 addition & 1 deletion src/lib/ipc/IpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ IpcServer::~IpcServer()
for (it = m_clients.begin(); it != m_clients.end(); it++) {
deleteClient(*it);
}
m_clients.empty();
m_clients.clear();
ARCH->unlockMutex(m_clientsMutex);
ARCH->closeMutex(m_clientsMutex);

Expand Down
2 changes: 2 additions & 0 deletions src/lib/net/SecureSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SecureSocket::SecureSocket(
IEventQueue* events,
SocketMultiplexer* socketMultiplexer) :
TCPSocket(events, socketMultiplexer),
m_ssl(nullptr),
m_secureReady(false),
m_fatal(false)
{
Expand All @@ -67,6 +68,7 @@ SecureSocket::SecureSocket(
SocketMultiplexer* socketMultiplexer,
ArchSocket socket) :
TCPSocket(events, socketMultiplexer, socket),
m_ssl(nullptr),
m_secureReady(false),
m_fatal(false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/TCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ TCPSocket::doRead()
memset(buffer, 0, sizeof(buffer));
size_t bytesRead = 0;

bytesRead = (int) ARCH->readSocket(m_socket, buffer, sizeof(buffer));
bytesRead = ARCH->readSocket(m_socket, buffer, sizeof(buffer));

if (bytesRead > 0) {
bool wasEmpty = (m_inputBuffer.getSize() == 0);
Expand Down
6 changes: 5 additions & 1 deletion src/lib/platform/MSWindowsClipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ MSWindowsClipboard::empty()

// mark clipboard as being owned by synergy
HGLOBAL data = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, 1);
SetClipboardData(getOwnershipFormat(), data);
if (NULL == SetClipboardData(getOwnershipFormat(), data)) {
LOG((CLOG_DEBUG "failed to set clipboard data"));
GlobalFree(data);
return false;
}

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/platform/MSWindowsDesks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void
MSWindowsDesks::destroyClass(ATOM windowClass) const
{
if (windowClass != 0) {
UnregisterClass(reinterpret_cast<LPCTSTR>(windowClass),
UnregisterClass(MAKEINTATOM(windowClass),
MSWindowsScreen::getWindowInstance());
}
}
Expand All @@ -437,7 +437,7 @@ MSWindowsDesks::createWindow(ATOM windowClass, const char* name) const
{
HWND window = CreateWindowEx(WS_EX_TRANSPARENT |
WS_EX_TOOLWINDOW,
reinterpret_cast<LPCTSTR>(windowClass),
MAKEINTATOM(windowClass),
name,
WS_POPUP,
0, 0, 1, 1,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/platform/MSWindowsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ void
MSWindowsScreen::destroyClass(ATOM windowClass) const
{
if (windowClass != 0) {
UnregisterClass(reinterpret_cast<LPCTSTR>(windowClass), s_windowInstance);
UnregisterClass(MAKEINTATOM(windowClass), s_windowInstance);
}
}

Expand All @@ -868,7 +868,7 @@ MSWindowsScreen::createWindow(ATOM windowClass, const char* name) const
HWND window = CreateWindowEx(WS_EX_TOPMOST |
WS_EX_TRANSPARENT |
WS_EX_TOOLWINDOW,
reinterpret_cast<LPCTSTR>(windowClass),
MAKEINTATOM(windowClass),
name,
WS_POPUP,
0, 0, 1, 1,
Expand All @@ -889,7 +889,7 @@ MSWindowsScreen::createDropWindow(ATOM windowClass, const char* name) const
WS_EX_TOPMOST |
WS_EX_TRANSPARENT |
WS_EX_ACCEPTFILES,
reinterpret_cast<LPCTSTR>(m_class),
MAKEINTATOM(m_class),
name,
WS_POPUP,
0, 0, m_dropWindowSize, m_dropWindowSize,
Expand Down Expand Up @@ -1129,7 +1129,7 @@ MSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
KeyModifierMask oldState = pollActiveModifiers();

// check for autorepeat
if (m_keyState->testAutoRepeat(down, (lParam & 0x40000000u) == 1, button)) {
if (m_keyState->testAutoRepeat(down, (lParam & 0x40000000u), button)) {
lParam |= 0x40000000u;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib/platform/MSWindowsScreenSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ MSWindowsScreenSaver::MSWindowsScreenSaver() :
m_process(NULL),
m_watch(NULL),
m_threadID(0),
m_msg(0),
m_wParam(0),
m_lParam(0),
m_active(false)
{
// check if screen saver is enabled
Expand Down
2 changes: 1 addition & 1 deletion src/lib/platform/MSWindowsSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ MSWindowsSession::getActiveDesktopName()
CloseDesktop(hd);
}
}
catch (std::exception error) {
catch (std::exception& error) {
LOG((CLOG_ERR "failed to get active desktop name: %s", error.what()));
}

Expand Down
27 changes: 5 additions & 22 deletions src/lib/platform/MSWindowsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,14 @@
String
MSWindowsUtil::getString(HINSTANCE instance, DWORD id)
{
char buffer[1024];
int size = static_cast<int>(sizeof(buffer) / sizeof(buffer[0]));
char* msg = buffer;
char* msg = NULL;
int n = LoadString(instance, id, reinterpret_cast<LPSTR>(&msg), 0);

// load string
int n = LoadString(instance, id, msg, size);
msg[n] = '\0';
if (n < size) {
return msg;
if (n <= 0) {
return String();
}

// not enough buffer space. keep trying larger buffers until
// we get the whole string.
msg = NULL;
do {
size <<= 1;
delete[] msg;
char* msg = new char[size];
n = LoadString(instance, id, msg, size);
} while (n == size);
msg[n] = '\0';

String result(msg);
delete[] msg;
return result;
return String (msg, n);
}

String
Expand Down
Loading

0 comments on commit 0953ac0

Please sign in to comment.