Skip to content

Commit 118731d

Browse files
Merge pull request #2271 from kevinbackhouse/signed-shift
Fix some "signed shift" warnings
2 parents a5c521e + 7f673c7 commit 118731d

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

app/exiv2.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ std::string parseEscapes(const std::string& input) {
14651465
break;
14661466
case 'u': // Escaping of unicode
14671467
if (input.length() >= 4 && input.length() - 4 > i) {
1468-
int acc = 0;
1468+
uint32_t acc = 0;
14691469
for (int j = 0; j < 4; ++j) {
14701470
++i;
14711471
acc <<= 4;
@@ -1476,19 +1476,19 @@ std::string parseEscapes(const std::string& input) {
14761476
} else if (input[i] >= 'A' && input[i] <= 'F') {
14771477
acc |= input[i] - 'A' + 10;
14781478
} else {
1479-
acc = -1;
1479+
acc = 0xFFFFFFFF;
14801480
break;
14811481
}
14821482
}
1483-
if (acc == -1) {
1483+
if (acc == 0xFFFFFFFF) {
14841484
result.push_back('\\');
14851485
i = escapeStart;
14861486
break;
14871487
}
14881488

14891489
std::string ucs2toUtf8;
1490-
ucs2toUtf8.push_back(static_cast<char>((acc & 0xff00) >> 8));
1491-
ucs2toUtf8.push_back(static_cast<char>(acc & 0x00ff));
1490+
ucs2toUtf8.push_back(static_cast<char>((acc & 0xff00U) >> 8));
1491+
ucs2toUtf8.push_back(static_cast<char>(acc & 0x00ffU));
14921492

14931493
if (Exiv2::convertStringCharset(ucs2toUtf8, "UCS-2BE", "UTF-8")) {
14941494
result.append(ucs2toUtf8);

src/canonmn_int.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,10 +2716,10 @@ std::ostream& CanonMakerNote::printSi0x000e(std::ostream& os, const Value& value
27162716
if (value.typeId() != unsignedShort || value.count() == 0)
27172717
return os << value;
27182718

2719-
const auto l = value.toInt64();
2720-
const auto num = (l & 0xf000) >> 12;
2719+
const auto l = value.toUint32();
2720+
const auto num = (l & 0xf000U) >> 12;
27212721
os << num << " focus points; ";
2722-
const auto used = l & 0x0fff;
2722+
const auto used = l & 0x0fffU;
27232723
if (used == 0) {
27242724
os << "none";
27252725
} else {

src/convert.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ void Converter::cnvExifFlash(const char* from, const char* to) {
782782
return;
783783
if (!prepareXmpTarget(to))
784784
return;
785-
auto value = pos->toInt64();
785+
auto value = pos->toUint32();
786786
if (!pos->value().ok()) {
787787
#ifndef SUPPRESS_WARNINGS
788788
EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
@@ -1052,7 +1052,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) {
10521052
unsigned short value = 0;
10531053

10541054
if (pos != xmpData_->end() && pos->count() > 0) {
1055-
auto fired = pos->toInt64();
1055+
auto fired = pos->toUint32();
10561056
if (pos->value().ok())
10571057
value |= fired & 1;
10581058
#ifndef SUPPRESS_WARNINGS
@@ -1063,7 +1063,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) {
10631063
}
10641064
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Return"));
10651065
if (pos != xmpData_->end() && pos->count() > 0) {
1066-
auto ret = pos->toInt64();
1066+
auto ret = pos->toUint32();
10671067
if (pos->value().ok())
10681068
value |= (ret & 3) << 1;
10691069
#ifndef SUPPRESS_WARNINGS
@@ -1074,7 +1074,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) {
10741074
}
10751075
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Mode"));
10761076
if (pos != xmpData_->end() && pos->count() > 0) {
1077-
auto mode = pos->toInt64();
1077+
auto mode = pos->toUint32();
10781078
if (pos->value().ok())
10791079
value |= (mode & 3) << 3;
10801080
#ifndef SUPPRESS_WARNINGS
@@ -1085,7 +1085,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) {
10851085
}
10861086
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Function"));
10871087
if (pos != xmpData_->end() && pos->count() > 0) {
1088-
auto function = pos->toInt64();
1088+
auto function = pos->toUint32();
10891089
if (pos->value().ok())
10901090
value |= (function & 1) << 5;
10911091
#ifndef SUPPRESS_WARNINGS
@@ -1097,7 +1097,7 @@ void Converter::cnvXmpFlash(const char* from, const char* to) {
10971097
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:RedEyeMode"));
10981098
if (pos != xmpData_->end()) {
10991099
if (pos->count() > 0) {
1100-
auto red = pos->toInt64();
1100+
auto red = pos->toUint32();
11011101
if (pos->value().ok())
11021102
value |= (red & 1) << 6;
11031103
#ifndef SUPPRESS_WARNINGS

src/image.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@ uint64_t Image::byteSwap(uint64_t value, bool bSwap) {
186186

187187
uint32_t Image::byteSwap(uint32_t value, bool bSwap) {
188188
uint32_t result = 0;
189-
result |= (value & 0x000000FF) << 24;
190-
result |= (value & 0x0000FF00) << 8;
191-
result |= (value & 0x00FF0000) >> 8;
192-
result |= (value & 0xFF000000) >> 24;
189+
result |= (value & 0x000000FFU) << 24;
190+
result |= (value & 0x0000FF00U) << 8;
191+
result |= (value & 0x00FF0000U) >> 8;
192+
result |= (value & 0xFF000000U) >> 24;
193193
return bSwap ? result : value;
194194
}
195195

196196
uint16_t Image::byteSwap(uint16_t value, bool bSwap) {
197197
uint16_t result = 0;
198-
result |= (value & 0x00FF) << 8;
199-
result |= (value & 0xFF00) >> 8;
198+
result |= (value & 0x00FFU) << 8;
199+
result |= (value & 0xFF00U) >> 8;
200200
return bSwap ? result : value;
201201
}
202202

src/nikonmn_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ std::ostream& Nikon3MakerNote::printAfPointsInFocus(std::ostream& os, const Valu
15001500

15011501
auto val = static_cast<uint16_t>(value.toInt64());
15021502
if (dModel)
1503-
val = (val >> 8) | ((val & 0x00ff) << 8);
1503+
val = (val >> 8) | ((val & 0x00ffU) << 8);
15041504

15051505
if (val == 0x07ff)
15061506
return os << _("All 11 Points");
@@ -3043,7 +3043,7 @@ std::ostream& Nikon3MakerNote::printFlashGroupBCControlData(std::ostream& os, co
30433043
}
30443044
std::ostringstream oss;
30453045
oss.copyfmt(os);
3046-
const auto temp = value.toInt64();
3046+
const auto temp = value.toUint32();
30473047

30483048
printTag<std::size(nikonFlashControlMode), nikonFlashControlMode>(os, (temp >> 4), data);
30493049
os << ", ";

src/pentaxmn_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ std::ostream& PentaxMakerNote::printFlashCompensation(std::ostream& os, const Va
964964
}
965965

966966
std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& value, const ExifData*) {
967-
const auto l0 = value.toInt64(0);
967+
const auto l0 = value.toUint32(0);
968968

969969
if (l0 < 10) {
970970
os << std::setprecision(2) << static_cast<float>(l0) / 3 << " EV";
@@ -973,7 +973,7 @@ std::ostream& PentaxMakerNote::printBracketing(std::ostream& os, const Value& va
973973
}
974974

975975
if (value.count() == 2) {
976-
const auto l1 = value.toInt64(1);
976+
const auto l1 = value.toUint32(1);
977977
os << " (";
978978
if (l1 == 0) {
979979
os << _("No extended bracketing");

src/pngchunk_int.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ std::string PngChunk::writeRawProfile(const std::string& profileData, const char
595595

596596
std::ostringstream oss;
597597
oss << '\n' << profileType << '\n' << std::setw(8) << profileData.size();
598-
const char* sp = profileData.data();
598+
const byte* sp = reinterpret_cast<const byte*>(profileData.data());
599599
for (std::string::size_type i = 0; i < profileData.size(); ++i) {
600600
if (i % 36 == 0)
601601
oss << '\n';
602-
oss << hex[((*sp >> 4) & 0x0f)];
603-
oss << hex[((*sp++) & 0x0f)];
602+
oss << hex[((*sp >> 4) & 0x0fU)];
603+
oss << hex[((*sp++) & 0x0fU)];
604604
}
605605
oss << '\n';
606606
return oss.str();

src/webpimage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,13 @@ void WebPImage::inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_
761761
}
762762

763763
/* set width - stored in 24bits*/
764-
int w = width - 1;
764+
uint32_t w = width - 1;
765765
data[4] = w & 0xFF;
766766
data[5] = (w >> 8) & 0xFF;
767767
data[6] = (w >> 16) & 0xFF;
768768

769769
/* set height - stored in 24bits */
770-
int h = height - 1;
770+
uint32_t h = height - 1;
771771
data[7] = h & 0xFF;
772772
data[8] = (h >> 8) & 0xFF;
773773
data[9] = (h >> 16) & 0xFF;

0 commit comments

Comments
 (0)