From 5c23b9ed7d55a2cd5f44b8ec3da2c8bdcac5c3a5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 3 Mar 2015 16:26:03 +0100 Subject: [PATCH] Fix bad signed/unsigned comparisons Either by casting, or switching to a more appropriate type for the variable. --- common/rdr/FileInStream.cxx | 2 +- common/rdr/RandomStream.cxx | 2 +- common/rdr/TLSInStream.cxx | 2 +- common/rfb/EncodeManager.cxx | 4 ++-- common/rfb/TightEncoder.cxx | 2 +- common/rfb/VNCServerST.cxx | 2 +- tests/conv.cxx | 2 +- tests/convperf.cxx | 8 ++++---- vncviewer/CConn.cxx | 2 +- vncviewer/cocoa.mm | 4 ++-- vncviewer/parameters.cxx | 12 ++++++------ win/rfb_win32/CleanDesktop.cxx | 2 +- win/rfb_win32/TsSessions.cxx | 4 ++-- win/vncconfig/Connections.h | 6 +++--- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/common/rdr/FileInStream.cxx b/common/rdr/FileInStream.cxx index 6d23aa2c..8d5c22e0 100644 --- a/common/rdr/FileInStream.cxx +++ b/common/rdr/FileInStream.cxx @@ -58,7 +58,7 @@ int FileInStream::pos() int FileInStream::overrun(int itemSize, int nItems, bool wait) { - if (itemSize > sizeof(b)) + if (itemSize > (int)sizeof(b)) throw Exception("FileInStream overrun: max itemSize exceeded"); if (end - ptr != 0) diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx index 7056c2cc..3fde18d1 100644 --- a/common/rdr/RandomStream.cxx +++ b/common/rdr/RandomStream.cxx @@ -44,7 +44,7 @@ RandomStream::RandomStream() #ifdef RFB_HAVE_WINCRYPT provider = 0; if (!CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, 0)) { - if (GetLastError() == NTE_BAD_KEYSET) { + if (GetLastError() == (DWORD)NTE_BAD_KEYSET) { if (!CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { fprintf(stderr, "RandomStream: unable to create keyset\n"); provider = 0; diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index 4d2c9ecb..21b60565 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -44,7 +44,7 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr str, void* data, size_t size) return -1; } - if (in->getend() - in->getptr() < size) + if (in->getend() - in->getptr() < (ptrdiff_t)size) size = in->getend() - in->getptr(); in->readBytes(data, size); diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index e6323870..4e133d31 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -152,7 +152,7 @@ EncodeManager::~EncodeManager() void EncodeManager::logStats() { - int i, j; + size_t i, j; unsigned rects; unsigned long long pixels, bytes, equivalent; @@ -603,7 +603,7 @@ void EncodeManager::writeSubRect(const Rect& rect, const PixelBuffer *pb) Encoder *encoder; struct RectInfo info; - int divisor, maxColours; + unsigned int divisor, maxColours; bool useRLE; EncoderType type; diff --git a/common/rfb/TightEncoder.cxx b/common/rfb/TightEncoder.cxx index ec19c2e0..fe2470b9 100644 --- a/common/rfb/TightEncoder.cxx +++ b/common/rfb/TightEncoder.cxx @@ -201,7 +201,7 @@ void TightEncoder::writePixels(const rdr::U8* buffer, const PixelFormat& pf, } while (count) { - int iter_count; + unsigned int iter_count; iter_count = sizeof(rgb)/3; if (iter_count > count) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index 51cb86cf..199524ec 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -544,7 +544,7 @@ inline bool VNCServerST::checkDefer() if (!deferPending) return true; - if (msSince(&deferStart) >= deferUpdateTime) + if (msSince(&deferStart) >= (unsigned)deferUpdateTime) return true; return false; diff --git a/tests/conv.cxx b/tests/conv.cxx index 2ee523a5..840f18dc 100644 --- a/tests/conv.cxx +++ b/tests/conv.cxx @@ -266,7 +266,7 @@ struct TestEntry tests[] = { static void doTests(const rfb::PixelFormat &dstpf, const rfb::PixelFormat &srcpf) { - int i; + size_t i; char dstb[256], srcb[256]; dstpf.print(dstb, sizeof(dstb)); diff --git a/tests/convperf.cxx b/tests/convperf.cxx index c8381d54..e4a3fd52 100644 --- a/tests/convperf.cxx +++ b/tests/convperf.cxx @@ -100,7 +100,7 @@ struct TestEntry tests[] = { static void doTests(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf) { - int i; + size_t i; char dstb[256], srcb[256]; dstpf.print(dstb, sizeof(dstb)); @@ -118,19 +118,19 @@ static void doTests(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf) int main(int argc, char **argv) { - int bufsize; + size_t bufsize; time_t t; char datebuffer[256]; - int i; + size_t i; bufsize = fbsize * fbsize * 4; fb1 = new rdr::U8[bufsize]; fb2 = new rdr::U8[bufsize]; - for (int i = 0;i < bufsize;i++) { + for (i = 0;i < bufsize;i++) { fb1[i] = rand(); fb2[i] = rand(); } diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index cf4f31b9..5935c177 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -134,7 +134,7 @@ CConn::~CConn() { OptionsDialog::removeCallback(handleOptions); - for (int i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++) + for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++) delete decoders[i]; if (desktop) diff --git a/vncviewer/cocoa.mm b/vncviewer/cocoa.mm index 09921000..e51cba9d 100644 --- a/vncviewer/cocoa.mm +++ b/vncviewer/cocoa.mm @@ -57,7 +57,7 @@ int cocoa_capture_display(Fl_Window *win, bool all_displays) if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess) return 1; - if (count != Fl::screen_count()) + if (count != (unsigned)Fl::screen_count()) return 1; #ifdef HAVE_FLTK_FULLSCREEN_SCREENS @@ -424,7 +424,7 @@ int cocoa_event_keysym(const void *event) NSEvent *nsevent; UInt16 key_code; - int i; + size_t i; NSString *chars; UInt32 modifiers; diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index 184af08f..29a5397d 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -202,7 +202,7 @@ static bool encodeValue(const char* val, char* dest, size_t destSize) { } else { - for (int j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) { + for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) { if (val[i] == replaceMap[j].first) { dest[pos] = '\\'; @@ -242,7 +242,7 @@ static bool decodeValue(const char* val, char* dest, size_t destSize) { // Check for escape sequences if (val[i] == '\\') { - for (int j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) { + for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) { if (val[i+1] == replaceMap[j].second) { dest[pos] = replaceMap[j].first; escapedCharacter = true; @@ -413,7 +413,7 @@ static void saveToReg(const char* servername) { setKeyString("ServerName", servername, &hKey); - for (int i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { + for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { if (dynamic_cast(parameterArray[i]) != NULL) { setKeyString(parameterArray[i]->getName(), *(StringParameter*)parameterArray[i], &hKey); } else if (dynamic_cast(parameterArray[i]) != NULL) { @@ -459,7 +459,7 @@ static char* loadFromReg() { int intValue = 0; char stringValue[buffersize]; - for (int i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { + for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { if (dynamic_cast(parameterArray[i]) != NULL) { if (getKeyString(parameterArray[i]->getName(), stringValue, buffersize, &hKey)) parameterArray[i]->setParam(stringValue); @@ -523,7 +523,7 @@ void saveViewerParameters(const char *filename, const char *servername) { if (encodeValue(servername, encodingBuffer, buffersize)) fprintf(f, "ServerName=%s\n", encodingBuffer); - for (int i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { + for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { if (dynamic_cast(parameterArray[i]) != NULL) { if (encodeValue(*(StringParameter*)parameterArray[i], encodingBuffer, buffersize)) fprintf(f, "%s=%s\n", ((StringParameter*)parameterArray[i])->getName(), encodingBuffer); @@ -635,7 +635,7 @@ char* loadViewerParameters(const char *filename) { } else { // Find and set the correct parameter - for (int i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { + for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { if (dynamic_cast(parameterArray[i]) != NULL) { if (strcasecmp(line, ((StringParameter*)parameterArray[i])->getName()) == 0) { diff --git a/win/rfb_win32/CleanDesktop.cxx b/win/rfb_win32/CleanDesktop.cxx index 52dc6bd7..bad95f0a 100644 --- a/win/rfb_win32/CleanDesktop.cxx +++ b/win/rfb_win32/CleanDesktop.cxx @@ -129,7 +129,7 @@ struct ActiveDesktop { vlog.error("failed to get desktop item count: %ld", hr); return false; } - for (unsigned int i=0; i 0)); - enableItem(IDC_HOST_DOWN, enable && (selected < count-1)); + enableItem(IDC_HOST_DOWN, enable && (selected+1 < count)); enableItem(IDC_HOST_EDIT, enable); setChanged(isChanged()); } -- 2.39.5