diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index e17fd6cb54..83ec152184 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -203,7 +203,7 @@ class BrotliDecoderWrapper { void BmffImage::brotliUncompress(const byte* compressedBuf, size_t compressedBufSize, DataBuf& arr) { BrotliDecoderWrapper decoder; size_t uncompressedLen = compressedBufSize * 2; // just a starting point - BrotliDecoderResult result; + BrotliDecoderResult result = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; int dos = 0; size_t available_in = compressedBufSize; const byte* next_in = compressedBuf; @@ -211,7 +211,7 @@ void BmffImage::brotliUncompress(const byte* compressedBuf, size_t compressedBuf byte* next_out; size_t total_out = 0; - do { + while (result != BROTLI_DECODER_RESULT_SUCCESS) { arr.alloc(uncompressedLen); available_out = uncompressedLen - total_out; next_out = arr.data() + total_out; @@ -234,7 +234,7 @@ void BmffImage::brotliUncompress(const byte* compressedBuf, size_t compressedBuf // something bad happened throw Error(ErrorCode::kerErrorMessage, BrotliDecoderErrorString(BrotliDecoderGetErrorCode(decoder.get()))); } - } while (result != BROTLI_DECODER_RESULT_SUCCESS); + }; if (result != BROTLI_DECODER_RESULT_SUCCESS) { throw Error(ErrorCode::kerFailedToReadImageData); diff --git a/src/minoltamn_int.cpp b/src/minoltamn_int.cpp index c1fa6edd5d..3192a037b9 100644 --- a/src/minoltamn_int.cpp +++ b/src/minoltamn_int.cpp @@ -1674,7 +1674,7 @@ static std::vector split(const std::string& str, const std::string& std::vector tokens; size_t prev = 0; size_t pos = 0; - do { + while (pos < str.length() && prev < str.length()) { pos = str.find(delim, prev); if (pos == std::string::npos) pos = str.length(); @@ -1682,7 +1682,7 @@ static std::vector split(const std::string& str, const std::string& if (!token.empty()) tokens.push_back(std::move(token)); prev = pos + delim.length(); - } while (pos < str.length() && prev < str.length()); + }; return tokens; } diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 82ae6d4161..9e62855777 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -334,10 +334,10 @@ std::string PngChunk::makeMetadataChunk(const std::string& metadata, MetadataId void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compressedTextSize, DataBuf& arr) { uLongf uncompressedLen = compressedTextSize * 2; // just a starting point - int zlibResult; + int zlibResult = Z_BUF_ERROR; int dos = 0; - do { + while (zlibResult == Z_BUF_ERROR) { arr.alloc(uncompressedLen); zlibResult = uncompress(arr.data(), &uncompressedLen, compressedText, compressedTextSize); if (zlibResult == Z_OK) { @@ -355,7 +355,7 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse // something bad happened throw Error(ErrorCode::kerFailedToReadImageData); } - } while (zlibResult == Z_BUF_ERROR); + }; if (zlibResult != Z_OK) { throw Error(ErrorCode::kerFailedToReadImageData); @@ -364,10 +364,10 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse std::string PngChunk::zlibCompress(const std::string& text) { auto compressedLen = static_cast(text.size() * 2); // just a starting point - int zlibResult; + int zlibResult = Z_BUF_ERROR; DataBuf arr; - do { + while (zlibResult == Z_BUF_ERROR) { arr.resize(compressedLen); zlibResult = compress2(arr.data(), &compressedLen, reinterpret_cast(text.data()), static_cast(text.size()), Z_BEST_COMPRESSION); @@ -390,7 +390,7 @@ std::string PngChunk::zlibCompress(const std::string& text) { // Something bad happened throw Error(ErrorCode::kerFailedToReadImageData); } - } while (zlibResult == Z_BUF_ERROR); + }; return {arr.c_str(), arr.size()}; diff --git a/src/pngimage.cpp b/src/pngimage.cpp index cf936b0739..0a2386b72e 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -75,7 +75,7 @@ static bool zlibToDataBuf(const byte* bytes, uLongf length, DataBuf& result) { uLongf uncompressedLen = length; // just a starting point int zlibResult = Z_BUF_ERROR; - do { + while (zlibResult == Z_BUF_ERROR) { result.alloc(uncompressedLen); zlibResult = uncompress(result.data(), &uncompressedLen, bytes, length); // if result buffer is large than necessary, redo to fit perfectly. @@ -95,7 +95,7 @@ static bool zlibToDataBuf(const byte* bytes, uLongf length, DataBuf& result) { else uncompressedLen *= 2; } - } while (zlibResult == Z_BUF_ERROR); + }; return zlibResult == Z_OK; } @@ -104,7 +104,7 @@ static bool zlibToCompressed(const byte* bytes, uLongf length, DataBuf& result) uLongf compressedLen = length; // just a starting point int zlibResult = Z_BUF_ERROR; - do { + while (zlibResult == Z_BUF_ERROR) { result.alloc(compressedLen); zlibResult = compress(result.data(), &compressedLen, bytes, length); if (zlibResult == Z_BUF_ERROR) { @@ -116,7 +116,7 @@ static bool zlibToCompressed(const byte* bytes, uLongf length, DataBuf& result) result.alloc(compressedLen); zlibResult = compress(result.data(), &compressedLen, bytes, length); } - } while (zlibResult == Z_BUF_ERROR); + }; return zlibResult == Z_OK; } @@ -443,9 +443,10 @@ void PngImage::readMetadata() { } else if (chunkType == "iCCP") { // The ICC profile name can vary from 1-79 characters. uint32_t iccOffset = 0; - do { + while (chunkData.read_uint8(iccOffset) != 0x00) { enforce(iccOffset < 80 && iccOffset < chunkLength, Exiv2::ErrorCode::kerCorruptedMetadata); - } while (chunkData.read_uint8(iccOffset++) != 0x00); + ++iccOffset; + }; profileName_ = std::string(chunkData.c_str(), iccOffset - 1); ++iccOffset; // +1 = 'compressed' flag diff --git a/src/types.cpp b/src/types.cpp index 88381372ed..210a784f07 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -460,11 +460,12 @@ void hexdump(std::ostream& os, const byte* buf, size_t len, size_t offset) { while (i < len) { os << " " << std::setw(4) << std::setfill('0') << std::hex << i + offset << " "; std::ostringstream ss; - do { + while (i < len && i % 16 != 0) { byte c = buf[i]; os << std::setw(2) << std::setfill('0') << std::right << std::hex << static_cast(c) << " "; ss << (static_cast(c) >= 31 && static_cast(c) < 127 ? static_cast(buf[i]) : '.'); - } while (++i < len && i % 16 != 0); + ++i; + }; std::string::size_type width = 9 + (((i - 1) % 16 + 1) * 3); os << (width > pos ? "" : align.substr(width)) << ss.str() << "\n"; }