From 7f673c766da6054abe9e0aa6c3da08acbc345443 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Wed, 6 Jul 2022 22:22:30 +0100 Subject: [PATCH] Fix some "signed shift" warnings --- app/exiv2.cpp | 10 +++++----- src/canonmn_int.cpp | 6 +++--- src/convert.cpp | 12 ++++++------ src/image.cpp | 12 ++++++------ src/nikonmn_int.cpp | 4 ++-- src/pentaxmn_int.cpp | 4 ++-- src/pngchunk_int.cpp | 6 +++--- src/webpimage.cpp | 4 ++-- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index a81f2123..65e86019 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -1465,7 +1465,7 @@ std::string parseEscapes(const std::string& input) { break; case 'u': // Escaping of unicode if (input.length() >= 4 && input.length() - 4 > i) { - int acc = 0; + uint32_t acc = 0; for (int j = 0; j < 4; ++j) { ++i; acc <<= 4; @@ -1476,19 +1476,19 @@ std::string parseEscapes(const std::string& input) { } else if (input[i] >= 'A' && input[i] <= 'F') { acc |= input[i] - 'A' + 10; } else { - acc = -1; + acc = 0xFFFFFFFF; break; } } - if (acc == -1) { + if (acc == 0xFFFFFFFF) { result.push_back('\\'); i = escapeStart; break; } std::string ucs2toUtf8; - ucs2toUtf8.push_back(static_cast((acc & 0xff00) >> 8)); - ucs2toUtf8.push_back(static_cast(acc & 0x00ff)); + ucs2toUtf8.push_back(static_cast((acc & 0xff00U) >> 8)); + ucs2toUtf8.push_back(static_cast(acc & 0x00ffU)); if (Exiv2::convertStringCharset(ucs2toUtf8, "UCS-2BE", "UTF-8")) { result.append(ucs2toUtf8); diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index c67ac888..a6785f56 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2716,10 +2716,10 @@ std::ostream& CanonMakerNote::printSi0x000e(std::ostream& os, const Value& value if (value.typeId() != unsignedShort || value.count() == 0) return os << value; - const auto l = value.toInt64(); - const auto num = (l & 0xf000) >> 12; + const auto l = value.toUint32(); + const auto num = (l & 0xf000U) >> 12; os << num << " focus points; "; - const auto used = l & 0x0fff; + const auto used = l & 0x0fffU; if (used == 0) { os << "none"; } else { diff --git a/src/convert.cpp b/src/convert.cpp index de9aafac..fbe53d60 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -782,7 +782,7 @@ void Converter::cnvExifFlash(const char* from, const char* to) { return; if (!prepareXmpTarget(to)) return; - auto value = pos->toInt64(); + auto value = pos->toUint32(); if (!pos->value().ok()) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to convert " << from << " to " << to << "\n"; @@ -1052,7 +1052,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) { unsigned short value = 0; if (pos != xmpData_->end() && pos->count() > 0) { - auto fired = pos->toInt64(); + auto fired = pos->toUint32(); if (pos->value().ok()) value |= fired & 1; #ifndef SUPPRESS_WARNINGS @@ -1063,7 +1063,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) { } pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Return")); if (pos != xmpData_->end() && pos->count() > 0) { - auto ret = pos->toInt64(); + auto ret = pos->toUint32(); if (pos->value().ok()) value |= (ret & 3) << 1; #ifndef SUPPRESS_WARNINGS @@ -1074,7 +1074,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) { } pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Mode")); if (pos != xmpData_->end() && pos->count() > 0) { - auto mode = pos->toInt64(); + auto mode = pos->toUint32(); if (pos->value().ok()) value |= (mode & 3) << 3; #ifndef SUPPRESS_WARNINGS @@ -1085,7 +1085,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) { } pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Function")); if (pos != xmpData_->end() && pos->count() > 0) { - auto function = pos->toInt64(); + auto function = pos->toUint32(); if (pos->value().ok()) value |= (function & 1) << 5; #ifndef SUPPRESS_WARNINGS @@ -1097,7 +1097,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) { pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:RedEyeMode")); if (pos != xmpData_->end()) { if (pos->count() > 0) { - auto red = pos->toInt64(); + auto red = pos->toUint32(); if (pos->value().ok()) value |= (red & 1) << 6; #ifndef SUPPRESS_WARNINGS diff --git a/src/image.cpp b/src/image.cpp index caf3cf09..13715ddd 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -186,17 +186,17 @@ uint64_t Image::byteSwap(uint64_t value, bool bSwap) { uint32_t Image::byteSwap(uint32_t value, bool bSwap) { uint32_t result = 0; - result |= (value & 0x000000FF) << 24; - result |= (value & 0x0000FF00) << 8; - result |= (value & 0x00FF0000) >> 8; - result |= (value & 0xFF000000) >> 24; + result |= (value & 0x000000FFU) << 24; + result |= (value & 0x0000FF00U) << 8; + result |= (value & 0x00FF0000U) >> 8; + result |= (value & 0xFF000000U) >> 24; return bSwap ? result : value; } uint16_t Image::byteSwap(uint16_t value, bool bSwap) { uint16_t result = 0; - result |= (value & 0x00FF) << 8; - result |= (value & 0xFF00) >> 8; + result |= (value & 0x00FFU) << 8; + result |= (value & 0xFF00U) >> 8; return bSwap ? result : value; } diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index 15236e6f..2c525656 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -1500,7 +1500,7 @@ std::ostream& Nikon3MakerNote::printAfPointsInFocus(std::ostream& os, const Valu auto val = static_cast(value.toInt64()); if (dModel) - val = (val >> 8) | ((val & 0x00ff) << 8); + val = (val >> 8) | ((val & 0x00ffU) << 8); if (val == 0x07ff) return os << _("All 11 Points"); @@ -3043,7 +3043,7 @@ std::ostream& Nikon3MakerNote::printFlashGroupBCControlData(std::ostream& os, co } std::ostringstream oss; oss.copyfmt(os); - const auto temp = value.toInt64(); + const auto temp = value.toUint32(); printTag(os, (temp >> 4), data); os << ", "; diff --git a/src/pentaxmn_int.cpp b/src/pentaxmn_int.cpp index 76c1c0bd..f60d8327 100644 --- a/src/pentaxmn_int.cpp +++ b/src/pentaxmn_int.cpp @@ -964,7 +964,7 @@ std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Va } std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*) { - const auto l0 = value.toInt64(0); + const auto l0 = value.toUint32(0); if (l0 < 10) { os << std::setprecision(2) << static_cast(l0) / 3 << " EV"; @@ -973,7 +973,7 @@ std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& va } if (value.count() == 2) { - const auto l1 = value.toInt64(1); + const auto l1 = value.toUint32(1); os << " ("; if (l1 == 0) { os << _("No extended bracketing"); diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 53ae8093..e7aec605 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -595,12 +595,12 @@ std::string PngChunk::writeRawProfile(const std::string& profileData, const char std::ostringstream oss; oss << '\n' << profileType << '\n' << std::setw(8) << profileData.size(); - const char* sp = profileData.data(); + const byte* sp = reinterpret_cast(profileData.data()); for (std::string::size_type i = 0; i < profileData.size(); ++i) { if (i % 36 == 0) oss << '\n'; - oss << hex[((*sp >> 4) & 0x0f)]; - oss << hex[((*sp++) & 0x0f)]; + oss << hex[((*sp >> 4) & 0x0fU)]; + oss << hex[((*sp++) & 0x0fU)]; } oss << '\n'; return oss.str(); diff --git a/src/webpimage.cpp b/src/webpimage.cpp index c6c80490..c658b080 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -761,13 +761,13 @@ void WebPImage::inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_ } /* set width - stored in 24bits*/ - int w = width - 1; + uint32_t w = width - 1; data[4] = w & 0xFF; data[5] = (w >> 8) & 0xFF; data[6] = (w >> 16) & 0xFF; /* set height - stored in 24bits */ - int h = height - 1; + uint32_t h = height - 1; data[7] = h & 0xFF; data[8] = (h >> 8) & 0xFF; data[9] = (h >> 16) & 0xFF;