From 213f4e25793308f779271cf50d82d3782de2b854 Mon Sep 17 00:00:00 2001 From: harry Date: Sat, 28 Jan 2023 16:24:04 -0500 Subject: [PATCH] More fixes for int compare sign mismatch warnings in Qt TAS Editor. --- src/drivers/Qt/TasEditor/greenzone.cpp | 9 +++--- src/drivers/Qt/TasEditor/inputlog.cpp | 8 +++--- src/drivers/Qt/TasEditor/laglog.cpp | 38 ++++++++++++++------------ 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/drivers/Qt/TasEditor/greenzone.cpp b/src/drivers/Qt/TasEditor/greenzone.cpp index 837009ab..d211f400 100644 --- a/src/drivers/Qt/TasEditor/greenzone.cpp +++ b/src/drivers/Qt/TasEditor/greenzone.cpp @@ -359,7 +359,8 @@ void GREENZONE::save(EMUFILE *os, int save_type) // returns true if couldn't load bool GREENZONE::load(EMUFILE *is, unsigned int offset) { - int frame = 0, prev_frame = -1, size = 0; + int frame = 0, prev_frame = -1; + unsigned int size = 0; int last_tick = -1; char save_id[GREENZONE_ID_LEN]; @@ -375,7 +376,7 @@ bool GREENZONE::load(EMUFILE *is, unsigned int offset) return false; } // read "GREENZONE" string - if ((int)is->fread(save_id, GREENZONE_ID_LEN) < GREENZONE_ID_LEN) goto error; + if (is->fread(save_id, GREENZONE_ID_LEN) < GREENZONE_ID_LEN) goto error; if (!strcmp(greenzone_skipsave_id, save_id)) { // string says to skip loading Greenzone @@ -419,7 +420,7 @@ bool GREENZONE::load(EMUFILE *is, unsigned int offset) // read LagLog lagLog.load(is); // read size - if (read32le(&size, is) && size >= 0 && size <= currMovieData.getNumRecords()) + if (read32le(&size, is) && size <= currMovieData.getNumRecords()) { greenzoneSize = size; savestates.resize(greenzoneSize); @@ -461,7 +462,7 @@ bool GREENZONE::load(EMUFILE *is, unsigned int offset) if ((int)savestates.size() <= frame) savestates.resize(frame + 1); savestates[frame].resize(size); - if ((int)is->fread(&savestates[frame][0], size) < size) break; + if (is->fread(&savestates[frame][0], size) < size) break; prev_frame = frame; // successfully read one Greenzone frame info } } diff --git a/src/drivers/Qt/TasEditor/inputlog.cpp b/src/drivers/Qt/TasEditor/inputlog.cpp index 1f1851b5..a4a40c2b 100644 --- a/src/drivers/Qt/TasEditor/inputlog.cpp +++ b/src/drivers/Qt/TasEditor/inputlog.cpp @@ -180,14 +180,14 @@ bool INPUTLOG::load(EMUFILE *is) inputType = tmp; // read data alreadyCompressed = true; - int comprlen; + unsigned int comprlen; uLongf destlen; // read and uncompress joysticks data destlen = size * BYTES_PER_JOYSTICK * joysticksPerFrame[inputType]; joysticks.resize(destlen); // read size if (!read32le(&comprlen, is)) return true; - if (comprlen <= 0) return true; + if (comprlen == 0) return true; compressedJoysticks.resize(comprlen); if (is->fread(&compressedJoysticks[0], comprlen) != comprlen) return true; int e = uncompress(&joysticks[0], &destlen, &compressedJoysticks[0], comprlen); @@ -212,7 +212,7 @@ bool INPUTLOG::load(EMUFILE *is) hotChanges.resize(destlen); // read size if (!read32le(&comprlen, is)) return true; - if (comprlen <= 0) return true; + if (comprlen == 0) return true; compressedHotChanges.resize(comprlen); if (is->fread(&compressedHotChanges[0], comprlen) != comprlen) return true; e = uncompress(&hotChanges[0], &destlen, &compressedHotChanges[0], comprlen); @@ -222,7 +222,7 @@ bool INPUTLOG::load(EMUFILE *is) } bool INPUTLOG::skipLoad(EMUFILE *is) { - int tmp; + unsigned int tmp; uint8 tmp1; // skip vars if (is->fseek(sizeof(int) + // size diff --git a/src/drivers/Qt/TasEditor/laglog.cpp b/src/drivers/Qt/TasEditor/laglog.cpp index 792c71c8..9df49777 100644 --- a/src/drivers/Qt/TasEditor/laglog.cpp +++ b/src/drivers/Qt/TasEditor/laglog.cpp @@ -33,14 +33,15 @@ void LAGLOG::reset(void) void LAGLOG::compressData(void) { - int len = lagLog.size() * sizeof(uint8); + unsigned int len = lagLog.size() * sizeof(uint8); if (len) { uLongf comprlen = (len>>9)+12 + len; compressedLagLog.resize(comprlen, LAGGED_UNKNOWN); compress(&compressedLagLog[0], &comprlen, (uint8*)&lagLog[0], len); compressedLagLog.resize(comprlen); - } else + } + else { // LagLog can even be empty compressedLagLog.resize(0); @@ -59,7 +60,7 @@ void LAGLOG::resetCompressedStatus(void) void LAGLOG::save(EMUFILE *os) { // write size - int size = lagLog.size(); + unsigned int size = lagLog.size(); write32le(size, os); if (size) { @@ -73,7 +74,7 @@ void LAGLOG::save(EMUFILE *os) // returns true if couldn't load bool LAGLOG::load(EMUFILE *is) { - int size; + unsigned int size; if (read32le(&size, is)) { alreadyCompressed = true; @@ -81,15 +82,16 @@ bool LAGLOG::load(EMUFILE *is) if (size) { // read and uncompress array - int comprlen; + unsigned int comprlen; uLongf destlen = size * sizeof(int); if (!read32le(&comprlen, is)) return true; - if (comprlen <= 0) return true; + if (comprlen == 0) return true; compressedLagLog.resize(comprlen); if (is->fread(&compressedLagLog[0], comprlen) != comprlen) return true; int e = uncompress((uint8*)&lagLog[0], &destlen, &compressedLagLog[0], comprlen); if (e != Z_OK && e != Z_BUF_ERROR) return true; - } else + } + else { compressedLagLog.resize(0); } @@ -100,7 +102,7 @@ bool LAGLOG::load(EMUFILE *is) } bool LAGLOG::skipLoad(EMUFILE *is) { - int size; + unsigned int size; if (read32le(&size, is)) { if (size) @@ -117,7 +119,7 @@ bool LAGLOG::skipLoad(EMUFILE *is) // ------------------------------------------------------------------------------------------------- void LAGLOG::invalidateFromFrame(int frame) { - if (frame >= 0 && frame < (int)lagLog.size()) + if (frame >= 0 && static_cast(frame) < lagLog.size()) { lagLog.resize(frame); alreadyCompressed = false; @@ -126,7 +128,7 @@ void LAGLOG::invalidateFromFrame(int frame) void LAGLOG::setLagInfo(int frame, bool lagFlag) { - if ((int)lagLog.size() <= frame) + if (lagLog.size() <= static_cast(frame)) lagLog.resize(frame + 1, LAGGED_UNKNOWN); if (lagFlag) @@ -138,18 +140,19 @@ void LAGLOG::setLagInfo(int frame, bool lagFlag) } void LAGLOG::eraseFrame(int frame, int numFrames) { - if (frame < (int)lagLog.size()) + if ( static_cast(frame) < lagLog.size()) { if (numFrames == 1) { // erase 1 frame lagLog.erase(lagLog.begin() + frame); alreadyCompressed = false; - } else if (numFrames > 1) + } + else if (numFrames > 1) { // erase many frames - if (frame + numFrames > (int)lagLog.size()) - numFrames = (int)lagLog.size() - frame; + if ( static_cast(frame + numFrames) > lagLog.size()) + numFrames = static_cast(lagLog.size()) - frame; lagLog.erase(lagLog.begin() + frame, lagLog.begin() + (frame + numFrames)); alreadyCompressed = false; } @@ -157,11 +160,12 @@ void LAGLOG::eraseFrame(int frame, int numFrames) } void LAGLOG::insertFrame(int frame, bool lagFlag, int numFrames) { - if (frame < (int)lagLog.size()) + if ( static_cast(frame) < lagLog.size()) { // insert lagLog.insert(lagLog.begin() + frame, numFrames, (lagFlag) ? LAGGED_YES : LAGGED_NO); - } else + } + else { // append lagLog.resize(frame + 1, LAGGED_UNKNOWN); @@ -180,7 +184,7 @@ int LAGLOG::getSize(void) } int LAGLOG::getLagInfoAtFrame(int frame) { - if (frame < (int)lagLog.size()) + if (static_cast(frame) < lagLog.size()) return lagLog[frame]; else return LAGGED_UNKNOWN;