Fix some "signed shift" warnings

This commit is contained in:
Kevin Backhouse 2022-07-06 22:22:30 +01:00
parent a5c521ea57
commit 7f673c766d
No known key found for this signature in database
GPG Key ID: 9DD01852EE40366E
8 changed files with 29 additions and 29 deletions

View File

@ -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<char>((acc & 0xff00) >> 8));
ucs2toUtf8.push_back(static_cast<char>(acc & 0x00ff));
ucs2toUtf8.push_back(static_cast<char>((acc & 0xff00U) >> 8));
ucs2toUtf8.push_back(static_cast<char>(acc & 0x00ffU));
if (Exiv2::convertStringCharset(ucs2toUtf8, "UCS-2BE", "UTF-8")) {
result.append(ucs2toUtf8);

View File

@ -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 {

View File

@ -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

View File

@ -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;
}

View File

@ -1500,7 +1500,7 @@ std::ostream& Nikon3MakerNote::printAfPointsInFocus(std::ostream& os, const Valu
auto val = static_cast<uint16_t>(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<std::size(nikonFlashControlMode), nikonFlashControlMode>(os, (temp >> 4), data);
os << ", ";

View File

@ -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<float>(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");

View File

@ -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<const byte*>(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();

View File

@ -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;