From 042b1964522834de2d44ca6f87d49e2c27fcb860 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 21 May 2022 16:43:19 -0700 Subject: [PATCH] clang-tidy: C casts to C++ Signed-off-by: Rosen Penev --- app/exiv2.cpp | 2 +- samples/addmoddel.cpp | 8 ++++---- samples/exifdata-test.cpp | 14 +++++++------- samples/iptceasy.cpp | 2 +- samples/remotetest.cpp | 12 ++++++------ samples/write2-test.cpp | 32 ++++++++++++++++---------------- samples/xmpsample.cpp | 2 +- src/convert.cpp | 2 +- src/crwimage.cpp | 2 +- src/exif.cpp | 8 ++++---- src/http.cpp | 2 +- src/makernote_int.cpp | 2 +- src/minoltamn_int.cpp | 4 ++-- src/nikonmn_int.cpp | 12 ++++++------ src/pngimage.cpp | 4 ++-- src/preview.cpp | 4 ++-- src/safe_op.hpp | 2 +- src/tiffcomposite_int.cpp | 22 +++++++++++++--------- src/tiffimage_int.cpp | 5 +++-- src/types.cpp | 2 +- src/webpimage.cpp | 8 ++++---- 21 files changed, 78 insertions(+), 73 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index d30cfcb5dd..7ff23c61d0 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -137,7 +137,7 @@ int main(int argc, char* const argv[]) { try { // Create the required action class - auto task = Action::TaskFactory::instance().create(Action::TaskType(params.action_)); + auto task = Action::TaskFactory::instance().create(static_cast(params.action_)); // Process all files auto filesCount = params.files_.size(); diff --git a/samples/addmoddel.cpp b/samples/addmoddel.cpp index 0ea379d806..272a83f8da 100644 --- a/samples/addmoddel.cpp +++ b/samples/addmoddel.cpp @@ -31,10 +31,10 @@ int main(int argc, char* const argv[]) { // This is the quickest way to add (simple) Exif data. If a metadatum for // a given key already exists, its value is overwritten. Otherwise a new // tag is added. - exifData["Exif.Image.Model"] = "Test 1"; // AsciiValue - exifData["Exif.Image.SamplesPerPixel"] = uint16_t(162); // UShortValue - exifData["Exif.Image.XResolution"] = -2; // LongValue - exifData["Exif.Image.YResolution"] = Exiv2::Rational(-2, 3); // RationalValue + exifData["Exif.Image.Model"] = "Test 1"; // AsciiValue + exifData["Exif.Image.SamplesPerPixel"] = static_cast(162); // UShortValue + exifData["Exif.Image.XResolution"] = -2; // LongValue + exifData["Exif.Image.YResolution"] = Exiv2::Rational(-2, 3); // RationalValue std::cout << "Added a few tags the quick way.\n"; // Create a ASCII string value (note the use of create) diff --git a/samples/exifdata-test.cpp b/samples/exifdata-test.cpp index 0451361293..b2a8fbc5ac 100644 --- a/samples/exifdata-test.cpp +++ b/samples/exifdata-test.cpp @@ -34,9 +34,9 @@ int main(int argc, char* const argv[]) { std::cout << "Copy construction, non-intrusive changes\n"; Exiv2::ExifData ed1(ed); ed1["Exif.Image.DateTime"] = "Sunday, 11am"; - ed1["Exif.Image.Orientation"] = uint16_t(2); + ed1["Exif.Image.Orientation"] = static_cast(2); ed1["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am"; - ed1["Exif.Photo.MeteringMode"] = uint16_t(1); + ed1["Exif.Photo.MeteringMode"] = static_cast(1); ed1["Exif.Iop.InteroperabilityIndex"] = "123"; // ed1["Exif.Thumbnail.Orientation"] = uint16_t(2); write(file, ed1); @@ -61,11 +61,11 @@ int main(int argc, char* const argv[]) { ed3["Exif.Thumbnail.Artist"] = "Test 6 Ifd1 tag"; ed3 = ed; ed3["Exif.Image.DateTime"] = "Sunday, 11am"; - ed3["Exif.Image.Orientation"] = uint16_t(2); + ed3["Exif.Image.Orientation"] = static_cast(2); ed3["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am"; - ed3["Exif.Photo.MeteringMode"] = uint16_t(1); + ed3["Exif.Photo.MeteringMode"] = static_cast(1); ed3["Exif.Iop.InteroperabilityIndex"] = "123"; - ed3["Exif.Thumbnail.Orientation"] = uint16_t(2); + ed3["Exif.Thumbnail.Orientation"] = static_cast(2); write(file, ed3); print(file); std::cout << "----------------------------------------------\n"; @@ -78,9 +78,9 @@ int main(int argc, char* const argv[]) { ed4["Exif.Image.DateTime"] = "Sunday, 11am and ten minutes"; ed4["Exif.Image.Orientation"] = "2 3 4 5"; ed4["Exif.Photo.DateTimeOriginal"] = "Sunday, 11am and ten minutes"; - ed4["Exif.Photo.MeteringMode"] = uint16_t(1); + ed4["Exif.Photo.MeteringMode"] = static_cast(1); ed4["Exif.Iop.InteroperabilityIndex"] = "123"; - ed4["Exif.Thumbnail.Orientation"] = uint16_t(2); + ed4["Exif.Thumbnail.Orientation"] = static_cast(2); write(file, ed4); print(file); diff --git a/samples/iptceasy.cpp b/samples/iptceasy.cpp index 45ecc87729..379b009580 100644 --- a/samples/iptceasy.cpp +++ b/samples/iptceasy.cpp @@ -23,7 +23,7 @@ int main(int argc, char* const argv[]) try { iptcData["Iptc.Application2.Headline"] = "The headline I am"; iptcData["Iptc.Application2.Keywords"] = "Yet another keyword"; iptcData["Iptc.Application2.DateCreated"] = "2004-8-3"; - iptcData["Iptc.Application2.Urgency"] = uint16_t(1); + iptcData["Iptc.Application2.Urgency"] = static_cast(1); iptcData["Iptc.Envelope.ModelVersion"] = 42; iptcData["Iptc.Envelope.TimeSent"] = "14:41:0-05:00"; iptcData["Iptc.Application2.RasterizedCaption"] = "230 42 34 2 90 84 23 146"; diff --git a/samples/remotetest.cpp b/samples/remotetest.cpp index d2907feb8d..0ebfb891ab 100644 --- a/samples/remotetest.cpp +++ b/samples/remotetest.cpp @@ -34,12 +34,12 @@ int main(int argc, char* const argv[]) { // set/add metadata std::cout << "Modify the metadata ...\n"; Exiv2::ExifData exifData; - exifData["Exif.Photo.UserComment"] = "Hello World"; // AsciiValue - exifData["Exif.Image.Software"] = "Exiv2"; // AsciiValue - exifData["Exif.Image.Copyright"] = "Exiv2"; // AsciiValue - exifData["Exif.Image.Make"] = "Canon"; // AsciiValue - exifData["Exif.Canon.OwnerName"] = "Tuan"; // UShortValue - exifData["Exif.CanonCs.LensType"] = uint16_t(65535); // LongValue + exifData["Exif.Photo.UserComment"] = "Hello World"; // AsciiValue + exifData["Exif.Image.Software"] = "Exiv2"; // AsciiValue + exifData["Exif.Image.Copyright"] = "Exiv2"; // AsciiValue + exifData["Exif.Image.Make"] = "Canon"; // AsciiValue + exifData["Exif.Canon.OwnerName"] = "Tuan"; // UShortValue + exifData["Exif.CanonCs.LensType"] = static_cast(65535); // LongValue Exiv2::Value::UniquePtr v = Exiv2::Value::create(Exiv2::asciiString); v->read("2013:06:09 14:30:30"); Exiv2::ExifKey key("Exif.Image.DateTime"); diff --git a/samples/write2-test.cpp b/samples/write2-test.cpp index b18365f590..b6773db9b9 100644 --- a/samples/write2-test.cpp +++ b/samples/write2-test.cpp @@ -56,11 +56,11 @@ int main(int argc, char* const argv[]) { edMn1["Exif.Image.Make"] = "Canon"; edMn1["Exif.Image.Model"] = "Canon PowerShot S40"; edMn1["Exif.Canon.0xabcd"] = "A Canon makernote tag"; - edMn1["Exif.CanonCs.0x0002"] = uint16_t(41); - edMn1["Exif.CanonSi.0x0005"] = uint16_t(42); - edMn1["Exif.CanonCf.0x0001"] = uint16_t(43); - edMn1["Exif.CanonPi.0x0001"] = uint16_t(44); - edMn1["Exif.CanonPa.0x0001"] = uint16_t(45); + edMn1["Exif.CanonCs.0x0002"] = static_cast(41); + edMn1["Exif.CanonSi.0x0005"] = static_cast(42); + edMn1["Exif.CanonCf.0x0001"] = static_cast(43); + edMn1["Exif.CanonPi.0x0001"] = static_cast(44); + edMn1["Exif.CanonPa.0x0001"] = static_cast(45); write(file, edMn1); print(file); @@ -69,8 +69,8 @@ int main(int argc, char* const argv[]) { image->readMetadata(); Exiv2::ExifData& rEd = image->exifData(); - rEd["Exif.CanonCs.0x0001"] = uint16_t(88); - rEd["Exif.CanonSi.0x0004"] = uint16_t(99); + rEd["Exif.CanonCs.0x0001"] = static_cast(88); + rEd["Exif.CanonSi.0x0004"] = static_cast(99); image->writeMetadata(); print(file); @@ -118,7 +118,7 @@ int main(int argc, char* const argv[]) { Exiv2::ExifData edMn7; edMn7["Exif.Image.Make"] = "OLYMPUS CORPORATION"; edMn7["Exif.Image.Model"] = "C8080WZ"; - edMn7["Exif.Olympus.0x0201"] = uint16_t(1); + edMn7["Exif.Olympus.0x0201"] = static_cast(1); write(file, edMn7); print(file); @@ -126,7 +126,7 @@ int main(int argc, char* const argv[]) { Exiv2::ExifData edMn8; edMn8["Exif.Image.Make"] = "Panasonic"; edMn8["Exif.Image.Model"] = "DMC-FZ5"; - edMn8["Exif.Panasonic.0x0001"] = uint16_t(1); + edMn8["Exif.Panasonic.0x0001"] = static_cast(1); write(file, edMn8); print(file); @@ -142,13 +142,13 @@ int main(int argc, char* const argv[]) { Exiv2::ExifData edMn10; edMn10["Exif.Image.Make"] = "Minolta"; edMn10["Exif.Image.Model"] = "A fancy Minolta camera"; - edMn10["Exif.Minolta.ColorMode"] = uint32_t(1); - edMn10["Exif.MinoltaCsNew.WhiteBalance"] = uint32_t(2); - edMn10["Exif.MinoltaCs5D.WhiteBalance"] = uint16_t(3); - edMn10["Exif.MinoltaCs5D.ColorTemperature"] = int16_t(-1); - edMn10["Exif.MinoltaCs7D.WhiteBalance"] = uint16_t(4); - edMn10["Exif.MinoltaCs7D.ExposureCompensation"] = int16_t(-2); - edMn10["Exif.MinoltaCs7D.ColorTemperature"] = int16_t(-3); + edMn10["Exif.Minolta.ColorMode"] = static_cast(1); + edMn10["Exif.MinoltaCsNew.WhiteBalance"] = static_cast(2); + edMn10["Exif.MinoltaCs5D.WhiteBalance"] = static_cast(3); + edMn10["Exif.MinoltaCs5D.ColorTemperature"] = static_cast(-1); + edMn10["Exif.MinoltaCs7D.WhiteBalance"] = static_cast(4); + edMn10["Exif.MinoltaCs7D.ExposureCompensation"] = static_cast(-2); + edMn10["Exif.MinoltaCs7D.ColorTemperature"] = static_cast(-3); write(file, edMn10); print(file); diff --git a/samples/xmpsample.cpp b/samples/xmpsample.cpp index 972620e70f..e02b3f0684 100644 --- a/samples/xmpsample.cpp +++ b/samples/xmpsample.cpp @@ -40,7 +40,7 @@ int main() try { xmpData["Xmp.dc.one"] = -1; xmpData["Xmp.dc.two"] = 3.1415; xmpData["Xmp.dc.three"] = Exiv2::Rational(5, 7); - xmpData["Xmp.dc.four"] = uint16_t(255); + xmpData["Xmp.dc.four"] = static_cast(255); xmpData["Xmp.dc.five"] = 256; xmpData["Xmp.dc.six"] = false; diff --git a/src/convert.cpp b/src/convert.cpp index 739eb3432c..de9aafacb1 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -1584,7 +1584,7 @@ bool convertStringCharsetIconv(std::string& str, const char* from, const char* t size_t outbytesleft = sizeof(outbuf); size_t rc = iconv(cd, &inptr, &inbytesleft, &outptr, &outbytesleft); const size_t outbytesProduced = sizeof(outbuf) - outbytesleft; - if (rc == size_t(-1) && errno != E2BIG) { + if (rc == static_cast(-1) && errno != E2BIG) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "iconv: " << strError() << " inbytesleft = " << inbytesleft << "\n"; #endif diff --git a/src/crwimage.cpp b/src/crwimage.cpp index 2a79e5609d..70cc1eb7f3 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -108,7 +108,7 @@ void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, size_t size) { // a hack to get absolute offset of preview image inside CRW structure auto preview = header.findComponent(0x2007, 0x0000); if (preview) { - (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormat"] = uint32_t(preview->pData() - pData); + (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormat"] = static_cast(preview->pData() - pData); (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormatLength"] = static_cast(preview->size()); } } // CrwParser::decode diff --git a/src/exif.cpp b/src/exif.cpp index f41b7d621f..8ca9f51765 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -301,7 +301,7 @@ int Exifdatum::ifdId() const { } const char* Exifdatum::ifdName() const { - return key_ ? Internal::ifdName(Internal::IfdId(key_->ifdId())) : ""; + return key_ ? Internal::ifdName(static_cast(key_->ifdId())) : ""; } int Exifdatum::idx() const { @@ -422,11 +422,11 @@ void ExifThumb::setJpegThumbnail(const std::string& path) { } void ExifThumb::setJpegThumbnail(const byte* buf, size_t size) { - exifData_["Exif.Thumbnail.Compression"] = uint16_t(6); + exifData_["Exif.Thumbnail.Compression"] = static_cast(6); Exifdatum& format = exifData_["Exif.Thumbnail.JPEGInterchangeFormat"]; - format = uint32_t(0); + format = static_cast(0); format.setDataArea(buf, size); - exifData_["Exif.Thumbnail.JPEGInterchangeFormatLength"] = uint32_t(size); + exifData_["Exif.Thumbnail.JPEGInterchangeFormatLength"] = static_cast(size); } void ExifThumb::erase() { diff --git a/src/http.cpp b/src/http.cpp index dc02eaa18e..32b7042edf 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -336,7 +336,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st if (n != FINISH || !OK(status)) { snprintf(buffer, sizeof buffer, "wsa_error = %d,n = %d,sleep_ = %d status = %d", WSAGetLastError(), n, - int(sleep_.count()), status); + static_cast(sleep_.count()), status); error(errors, buffer, nullptr, nullptr, 0); } else if (bSearching && OK(status)) { if (end) { diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 78562843f3..033743d00e 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -1036,7 +1036,7 @@ const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const ui std::string getExifModel(Exiv2::Internal::TiffComponent* pRoot) { // Lookup the Exif.Image.Model tag const auto value = getExifValue(pRoot, 0x0110, Exiv2::Internal::ifd0Id); - return (!value || value->count() == 0) ? std::string("") : std::string(value->toString()); + return (!value || value->count() == 0) ? std::string("") : static_cast(value->toString()); } void ncrypt(Exiv2::byte* pData, uint32_t size, uint32_t count, uint32_t serial) { diff --git a/src/minoltamn_int.cpp b/src/minoltamn_int.cpp index 34b66f3426..2155cb1e4b 100644 --- a/src/minoltamn_int.cpp +++ b/src/minoltamn_int.cpp @@ -583,7 +583,7 @@ std::ostream& MinoltaMakerNote::printMinoltaExposureManualBias5D(std::ostream& o std::ios::fmtflags f(os.flags()); std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(2) << (float(value.toInt64() - 128) / 24); + os << std::fixed << std::setprecision(2) << (static_cast(value.toInt64() - 128) / 24); os.copyfmt(oss); os.flags(f); return os; @@ -595,7 +595,7 @@ std::ostream& MinoltaMakerNote::printMinoltaExposureCompensation5D(std::ostream& std::ios::fmtflags f(os.flags()); std::ostringstream oss; oss.copyfmt(os); - os << std::fixed << std::setprecision(2) << (float(value.toInt64() - 300) / 100); + os << std::fixed << std::setprecision(2) << (static_cast(value.toInt64() - 300) / 100); os.copyfmt(oss); os.flags(f); return os; diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index 336bff46da..15236e6f21 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -3013,7 +3013,7 @@ std::ostream& Nikon3MakerNote::printFlashCompensation(std::ostream& os, const Va } std::ostringstream oss; oss.copyfmt(os); - float temp = (value.toFloat() / float(-6.0)); + float temp = (value.toFloat() / static_cast(-6.0)); if (temp == 0) os << 0; @@ -3064,7 +3064,7 @@ std::ostream& Nikon3MakerNote::printFlashGroupAData(std::ostream& os, const Valu std::ostringstream oss; oss.copyfmt(os); - double temp = value.toFloat() / double(-6.0); + double temp = value.toFloat() / (-6.0); auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.FlashGroupAControlData")); if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { @@ -3100,7 +3100,7 @@ std::ostream& Nikon3MakerNote::printFlashGroupBData(std::ostream& os, const Valu std::ostringstream oss; oss.copyfmt(os); - double temp = value.toFloat() / double(-6.0); + double temp = value.toFloat() / (-6.0); auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.FlashGroupBCControlData")); if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { @@ -3136,7 +3136,7 @@ std::ostream& Nikon3MakerNote::printFlashGroupCData(std::ostream& os, const Valu std::ostringstream oss; oss.copyfmt(os); - double temp = value.toFloat() / double(-6.0); + double temp = value.toFloat() / (-6.0); auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.FlashGroupBCControlData")); if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { @@ -3172,8 +3172,8 @@ std::ostream& Nikon3MakerNote::printTimeZone(std::ostream& os, const Value& valu std::ostringstream oss; oss.copyfmt(os); char sign = value.toInt64() < 0 ? '-' : '+'; - long h = long(std::abs(static_cast(value.toFloat() / 60.0F))) % 24; - long min = long(std::abs(static_cast(value.toFloat() - h * 60))) % 60; + long h = static_cast(std::abs(static_cast(value.toFloat() / 60.0F))) % 24; + long min = static_cast(std::abs(static_cast(value.toFloat() - h * 60))) % 60; os << std::fixed << "UTC " << sign << std::setw(2) << std::setfill('0') << h << ":" << std::setw(2) << std::setfill('0') << min; os.copyfmt(oss); diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 75d509e22b..a241554936 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -224,7 +224,7 @@ void PngImage::printStructure(std::ostream& out, PrintStructureOption option, in // test that we haven't hit EOF, or wanting to read excessive data long restore = io_->tell(); - if (restore == -1 || dataOffset > uint32_t(0x7FFFFFFF) || dataOffset > imgSize - restore) { + if (restore == -1 || dataOffset > static_cast(0x7FFFFFFF) || dataOffset > imgSize - restore) { throw Exiv2::Error(ErrorCode::kerFailedToReadImageData); } @@ -408,7 +408,7 @@ void PngImage::readMetadata() { // Decode chunk data length. uint32_t chunkLength = cheaderBuf.read_uint32(0, Exiv2::bigEndian); long pos = io_->tell(); - if (pos == -1 || chunkLength > uint32_t(0x7FFFFFFF) || chunkLength > imgSize - pos) { + if (pos == -1 || chunkLength > static_cast(0x7FFFFFFF) || chunkLength > imgSize - pos) { throw Exiv2::Error(ErrorCode::kerFailedToReadImageData); } diff --git a/src/preview.cpp b/src/preview.cpp index 5154257458..2d5780062d 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -348,7 +348,7 @@ PreviewProperties Loader::getProperties() const { } PreviewId Loader::getNumLoaders() { - return PreviewId(std::size(loaderList_)); + return static_cast(std::size(loaderList_)); } LoaderNative::LoaderNative(PreviewId id, const Image& image, int parIdx) : Loader(id, image) { @@ -752,7 +752,7 @@ DataBuf LoaderTiff::getData() const { // Fix compression value in the CR2 IFD2 image if (0 == strcmp(group_, "Image2") && image_.mimeType() == "image/x-canon-cr2") { - preview["Exif.Image.Compression"] = uint16_t(1); + preview["Exif.Image.Compression"] = static_cast(1); } // write new image diff --git a/src/safe_op.hpp b/src/safe_op.hpp index 3b924d3e0c..27f542afe4 100644 --- a/src/safe_op.hpp +++ b/src/safe_op.hpp @@ -46,7 +46,7 @@ namespace Internal { */ template struct is_signed { - enum { VALUE = T(-1) < T(0) }; + enum { VALUE = static_cast(-1) < static_cast(0) }; }; /*! diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 5a41d9765a..f488c5e694 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -54,7 +54,7 @@ void IoWrapper::setTarget(int id, int64_t target) { throw Error(ErrorCode::kerOffsetOutOfRange); } if (pow_) - pow_->setTarget(OffsetWriter::OffsetId(id), static_cast(target)); + pow_->setTarget(static_cast(id), static_cast(target)); } TiffComponent::TiffComponent(uint16_t tag, IfdId group) : tag_(tag), group_(group) { @@ -387,7 +387,7 @@ bool TiffBinaryArray::initialize(IfdId group) { if (arraySet_[idx].cfg_.group_ == group) { arrayCfg_ = &arraySet_[idx].cfg_; arrayDef_ = arraySet_[idx].def_; - defSize_ = int(arraySet_[idx].defSize_); + defSize_ = static_cast(arraySet_[idx].defSize_); return true; } } @@ -402,7 +402,7 @@ bool TiffBinaryArray::initialize(TiffComponent* pRoot) { if (idx > -1) { arrayCfg_ = &arraySet_[idx].cfg_; arrayDef_ = arraySet_[idx].def_; - defSize_ = int(arraySet_[idx].defSize_); + defSize_ = static_cast(arraySet_[idx].defSize_); } return idx > -1; } @@ -824,7 +824,7 @@ uint32_t TiffComponent::write(IoWrapper& ioWrapper, ByteOrder byteOrder, int64_t uint32_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64_t offset, uint32_t valueIdx, uint32_t dataIdx, uint32_t& imageIdx) { - bool isRootDir = (imageIdx == uint32_t(-1)); + bool isRootDir = (imageIdx == static_cast(-1)); // Number of components to write const size_t compCount = count(); @@ -934,7 +934,8 @@ uint32_t TiffDirectory::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64 // 4th: Write next-IFD if (pNext_ && sizeNext) { - idx += pNext_->write(ioWrapper, byteOrder, offset + idx, uint32_t(-1), uint32_t(-1), imageIdx); + idx += pNext_->write(ioWrapper, byteOrder, offset + idx, static_cast(-1), static_cast(-1), + imageIdx); } // 5th, at the root directory level only: write image data @@ -1064,7 +1065,8 @@ uint32_t TiffMnEntry::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64_t if (!mn_) { return TiffEntryBase::doWrite(ioWrapper, byteOrder, offset, valueIdx, dataIdx, imageIdx); } - return mn_->write(ioWrapper, byteOrder, offset + valueIdx, uint32_t(-1), uint32_t(-1), imageIdx); + return mn_->write(ioWrapper, byteOrder, offset + valueIdx, static_cast(-1), static_cast(-1), + imageIdx); } // TiffMnEntry::doWrite uint32_t TiffIfdMakernote::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, int64_t offset, uint32_t /*valueIdx*/, @@ -1072,7 +1074,8 @@ uint32_t TiffIfdMakernote::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, in mnOffset_ = static_cast(offset); setImageByteOrder(byteOrder); auto len = static_cast(writeHeader(ioWrapper, this->byteOrder())); - len += ifd_.write(ioWrapper, this->byteOrder(), offset - baseOffset() + len, uint32_t(-1), uint32_t(-1), imageIdx); + len += ifd_.write(ioWrapper, this->byteOrder(), offset - baseOffset() + len, static_cast(-1), + static_cast(-1), imageIdx); return len; } // TiffIfdMakernote::doWrite @@ -1195,7 +1198,8 @@ uint32_t TiffSubIfd::doWriteData(IoWrapper& ioWrapper, ByteOrder byteOrder, int6 uint32_t& imageIdx) const { uint32_t len = 0; for (auto&& ifd : ifds_) { - len += ifd->write(ioWrapper, byteOrder, offset + dataIdx + len, uint32_t(-1), uint32_t(-1), imageIdx); + len += ifd->write(ioWrapper, byteOrder, offset + dataIdx + len, static_cast(-1), + static_cast(-1), imageIdx); } // Align data to word boundary uint32_t align = (len & 1); @@ -1483,7 +1487,7 @@ static const TagInfo* findTagInfo(uint16_t tag, IfdId group) { // ************************************************************************* // free functions TypeId toTypeId(TiffType tiffType, uint16_t tag, IfdId group) { - auto ti = TypeId(tiffType); + auto ti = static_cast(tiffType); // On the fly type conversion for Exif.Photo.UserComment, Exif.GPSProcessingMethod, GPSAreaInformation if (const TagInfo* pTag = ti == undefined ? findTagInfo(tag, group) : nullptr) { if (pTag->typeId_ == comment) { diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index f0dcee4836..1b34a3241f 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -1892,8 +1892,9 @@ WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size DataBuf header = pHeader->write(); auto tempIo = MemIo(); IoWrapper ioWrapper(tempIo, header.c_data(), header.size(), pOffsetWriter); - auto imageIdx(uint32_t(-1)); - createdTree->write(ioWrapper, pHeader->byteOrder(), header.size(), uint32_t(-1), uint32_t(-1), imageIdx); + auto imageIdx(static_cast(-1)); + createdTree->write(ioWrapper, pHeader->byteOrder(), header.size(), static_cast(-1), + static_cast(-1), imageIdx); if (pOffsetWriter) pOffsetWriter->writeOffsets(tempIo); io.transfer(tempIo); // may throw diff --git a/src/types.cpp b/src/types.cpp index bea58c40ef..8cb4b6181c 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -465,7 +465,7 @@ void hexdump(std::ostream& os, const byte* buf, size_t len, size_t offset) { do { 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 ? char(buf[i]) : '.'); + ss << (static_cast(c) >= 31 && static_cast(c) < 127 ? static_cast(buf[i]) : '.'); } while (++i < len && i % 16 != 0); std::string::size_type width = 9 + ((i - 1) % 16 + 1) * 3; os << (width > pos ? "" : align.substr(width)) << ss.str() << "\n"; diff --git a/src/webpimage.cpp b/src/webpimage.cpp index c1806c78e9..dbdfde18e8 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -23,8 +23,8 @@ namespace { [[maybe_unused]] std::string binaryToHex(const uint8_t* data, size_t size) { std::stringstream hexOutput; - auto tl = size_t(size / 16) * 16; - auto tl_offset = size_t(size) - tl; + auto tl = static_cast(size / 16) * 16; + auto tl_offset = size - tl; for (size_t loop = 0; loop < size; loop++) { if (data[loop] < 16) { @@ -37,8 +37,8 @@ namespace { if ((loop % 16) == 15 || loop == (tl + tl_offset - 1)) { int max = 15; if (loop >= tl) { - max = int(tl_offset) - 1; - for (int offset = 0; offset < int(16 - tl_offset); offset++) { + max = static_cast(tl_offset) - 1; + for (int offset = 0; offset < static_cast(16 - tl_offset); offset++) { if ((offset % 8) == 7) { hexOutput << " "; }