From b4c90b5e16c17f9a2681df33676ea1c1da281c3d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 21 May 2022 16:33:35 -0700 Subject: [PATCH 1/3] clang-tidy: replace pointer magic with data() Signed-off-by: Rosen Penev --- samples/tiff-test.cpp | 2 +- src/crwimage.cpp | 2 +- src/image.cpp | 4 ++-- src/image_int.cpp | 4 ++-- src/jpgimage.cpp | 10 +++++----- src/photoshop.cpp | 2 +- src/pngchunk_int.cpp | 2 +- src/pngimage.cpp | 2 +- src/psdimage.cpp | 2 +- src/tiffvisitor_int.cpp | 2 +- src/value.cpp | 2 +- src/webpimage.cpp | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/samples/tiff-test.cpp b/samples/tiff-test.cpp index acd8e3dcb3..7b02d4b013 100644 --- a/samples/tiff-test.cpp +++ b/samples/tiff-test.cpp @@ -61,7 +61,7 @@ void mini1(const char* path) { enforce(wm == wmIntrusive, Exiv2::ErrorCode::kerErrorMessage, "encode returned an unexpected value"); std::cout << "Test 3: Wrote non-empty Exif data without original binary data:\n"; exifData.clear(); - ByteOrder bo = ExifParser::decode(exifData, &blob[0], blob.size()); + ByteOrder bo = ExifParser::decode(exifData, blob.data(), blob.size()); enforce(bo == bigEndian, Exiv2::ErrorCode::kerErrorMessage, "decode returned an unexpected value"); print(exifData); } diff --git a/src/crwimage.cpp b/src/crwimage.cpp index d9686ea42e..2a79e5609d 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -93,7 +93,7 @@ void CrwImage::writeMetadata() { // Write new buffer to file MemIo tempIo; - tempIo.write((!blob.empty() ? &blob[0] : nullptr), blob.size()); + tempIo.write((!blob.empty() ? blob.data() : nullptr), blob.size()); io_->close(); io_->transfer(tempIo); // may throw diff --git a/src/image.cpp b/src/image.cpp index ed6c090cac..208fe9c2ec 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -425,10 +425,10 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct io.seekOrThrow(offset, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // position std::vector bytes(count); // allocate memory // TODO: once we have C++11 use bytes.data() - io.readOrThrow(&bytes[0], count, ErrorCode::kerCorruptedMetadata); + io.readOrThrow(bytes.data(), count, ErrorCode::kerCorruptedMetadata); io.seekOrThrow(restore, BasicIo::beg, ErrorCode::kerCorruptedMetadata); // TODO: once we have C++11 use bytes.data() - IptcData::printStructure(out, makeSliceUntil(&bytes[0], count), depth); + IptcData::printStructure(out, makeSliceUntil(bytes.data(), count), depth); } } else if (option == kpsRecursive && tag == 0x927c /* MakerNote */ && count > 10) { const long restore = io.tell(); // save diff --git a/src/image_int.cpp b/src/image_int.cpp index df6420c312..51dc67220b 100644 --- a/src/image_int.cpp +++ b/src/image_int.cpp @@ -24,14 +24,14 @@ std::string stringFormat(const char* format, ...) { buffer.resize(need + 1); va_list args; // variable arg list va_start(args, format); // args start after format - rc = vsnprintf(&buffer[0], buffer.size(), format, args); + rc = vsnprintf(buffer.data(), buffer.size(), format, args); va_end(args); // free the args if (rc > 0) need = static_cast(rc); } while (buffer.size() <= need); if (rc > 0) - result = std::string(&buffer[0], need); + result = std::string(buffer.data(), need); return result; } diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index ae72625324..da9c32b06b 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -188,7 +188,7 @@ void JpegBase::readMetadata() { append(psBlob, buf.c_data(16), size - 16); } // Check whether psBlob is complete - if (!psBlob.empty() && Photoshop::valid(&psBlob[0], psBlob.size())) { + if (!psBlob.empty() && Photoshop::valid(psBlob.data(), psBlob.size())) { --search; foundCompletePsData = true; } @@ -263,7 +263,7 @@ void JpegBase::readMetadata() { const byte* record = nullptr; uint32_t sizeIptc = 0; uint32_t sizeHdr = 0; - const byte* pCur = &psBlob[0]; + const byte* pCur = psBlob.data(); const byte* pEnd = pCur + psBlob.size(); while (pCur < pEnd && 0 == Photoshop::locateIptcIrb(pCur, pEnd - pCur, &record, sizeHdr, sizeIptc)) { #ifdef EXIV2_DEBUG_MESSAGES @@ -274,7 +274,7 @@ void JpegBase::readMetadata() { } pCur = record + sizeHdr + sizeIptc + (sizeIptc & 1); } - if (!iptcBlob.empty() && IptcParser::decode(iptcData_, &iptcBlob[0], iptcBlob.size())) { + if (!iptcBlob.empty() && IptcParser::decode(iptcData_, iptcBlob.data(), iptcBlob.size())) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to decode IPTC metadata.\n"; #endif @@ -680,7 +680,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { // Append to psBlob append(psBlob, buf.c_data(16), buf.size() - 16); // Check whether psBlob is complete - if (!psBlob.empty() && Photoshop::valid(&psBlob[0], psBlob.size())) { + if (!psBlob.empty() && Photoshop::valid(psBlob.data(), psBlob.size())) { foundCompletePsData = true; } } else if (marker == com_ && skipCom == notfound) { @@ -750,7 +750,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { size_t exifSize = rawExif.size(); WriteMethod wm = ExifParser::encode(blob, pExifData, exifSize, bo, exifData_); if (wm == wmIntrusive) { - pExifData = !blob.empty() ? &blob[0] : nullptr; + pExifData = !blob.empty() ? blob.data() : nullptr; exifSize = blob.size(); } if (exifSize > 0) { diff --git a/src/photoshop.cpp b/src/photoshop.cpp index 526f2ea029..043a6eb07d 100644 --- a/src/photoshop.cpp +++ b/src/photoshop.cpp @@ -170,7 +170,7 @@ DataBuf Photoshop::setIptcIrb(const byte* pPsData, size_t sizePsData, const Iptc // Data is rounded to be even if (!psBlob.empty()) - rc = DataBuf(&psBlob[0], psBlob.size()); + rc = DataBuf(psBlob.data(), psBlob.size()); #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "IRB block at the end of Photoshop::setIptcIrb\n"; if (rc.empty()) diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index a046ebe033..53ae8093ae 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -246,7 +246,7 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize, pCur = record + sizeHdr + sizeIptc; pCur += (sizeIptc & 1); } - if (!iptcBlob.empty() && IptcParser::decode(pImage->iptcData(), &iptcBlob[0], iptcBlob.size())) { + if (!iptcBlob.empty() && IptcParser::decode(pImage->iptcData(), iptcBlob.data(), iptcBlob.size())) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to decode IPTC metadata.\n"; #endif diff --git a/src/pngimage.cpp b/src/pngimage.cpp index df4b1ec10c..75d509e22b 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -572,7 +572,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) { if (!blob.empty()) { static const char exifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}; std::string rawExif = - std::string(exifHeader, 6) + std::string(reinterpret_cast(&blob[0]), blob.size()); + std::string(exifHeader, 6) + std::string(reinterpret_cast(blob.data()), blob.size()); std::string chunk = PngChunk::makeMetadataChunk(rawExif, mdExif); if (outIo.write(reinterpret_cast(chunk.data()), chunk.size()) != chunk.size()) { throw Error(ErrorCode::kerImageWriteFailed); diff --git a/src/psdimage.cpp b/src/psdimage.cpp index 7e5d7b65cc..94ac778884 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -610,7 +610,7 @@ uint32_t PsdImage::writeExifData(const ExifData& exifData, BasicIo& out) { if (out.write(buf, 4) != 4) throw Error(ErrorCode::kerImageWriteFailed); // Write encoded Exif data - if (out.write(&blob[0], blob.size()) != blob.size()) + if (out.write(blob.data(), blob.size()) != blob.size()) throw Error(ErrorCode::kerImageWriteFailed); resLength += static_cast(blob.size()) + 12; if (blob.size() & 1) // even padding diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 82f6592c20..b7a39cebcb 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -557,7 +557,7 @@ void TiffEncoder::encodeXmp() { if (!xmpPacket.empty()) { // Set the XMP Exif tag to the new value auto value = Value::create(unsignedByte); - value->read(reinterpret_cast(&xmpPacket[0]), xmpPacket.size(), invalidByteOrder); + value->read(reinterpret_cast(xmpPacket.data()), xmpPacket.size(), invalidByteOrder); Exifdatum xmpDatum(xmpKey, value.get()); exifData_.add(xmpDatum); } diff --git a/src/value.cpp b/src/value.cpp index 5af114b028..526c57e736 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -490,7 +490,7 @@ size_t XmpValue::copy(byte* buf, ByteOrder /*byteOrder*/) const { write(os); std::string s = os.str(); if (!s.empty()) - std::memcpy(buf, &s[0], s.size()); + std::memcpy(buf, s.data(), s.size()); return s.size(); } diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 3ed1dbaa2e..c1806c78e9 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -377,7 +377,7 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) { ul2Data(data, static_cast(blob.size()), littleEndian); if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(ErrorCode::kerImageWriteFailed); - if (outIo.write(&blob[0], blob.size()) != blob.size()) { + if (outIo.write(blob.data(), blob.size()) != blob.size()) { throw Error(ErrorCode::kerImageWriteFailed); } if (outIo.tell() % 2) { From a98954a98e733ba6310ef92d0ef1fcc69ae98ff5 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 21 May 2022 17:06:36 -0700 Subject: [PATCH 2/3] clang-tidy: add missing special member functions Signed-off-by: Rosen Penev --- app/actions.hpp | 2 ++ app/exiv2app.hpp | 2 ++ include/exiv2/webpimage.hpp | 1 + src/crwimage_int.hpp | 4 ++++ src/makernote_int.hpp | 4 +++- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/actions.hpp b/app/actions.hpp index 62a1c557e3..ec89ef85fe 100644 --- a/app/actions.hpp +++ b/app/actions.hpp @@ -97,8 +97,10 @@ class TaskFactory { */ static TaskFactory& instance(); + ~TaskFactory() = default; //! Prevent copy construction: not implemented. TaskFactory(const TaskFactory&) = delete; + TaskFactory& operator=(const TaskFactory&) = delete; //! Destructor void cleanup(); diff --git a/app/exiv2app.hpp b/app/exiv2app.hpp index c12fce6130..8921045b1d 100644 --- a/app/exiv2app.hpp +++ b/app/exiv2app.hpp @@ -110,7 +110,9 @@ class Params : public Util::Getopt { static Params& instance(); //! Prevent copy-construction: not implemented. + ~Params() = default; Params(const Params&) = delete; + Params& operator=(const Params&) = delete; //! Enumerates print modes enum PrintMode { diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index 09e60b23d8..d9dda5a7dd 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -54,6 +54,7 @@ class EXIV2API WebPImage : public Image { [[nodiscard]] std::string mimeType() const override; //@} + ~WebPImage() = default; //! Copy constructor WebPImage(const WebPImage&) = delete; //! Assignment operator diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 4c09abf829..2c2318e9dc 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -330,6 +330,9 @@ class CiffDirectory : public CiffComponent { ~CiffDirectory() override; //@} + CiffDirectory(const CiffDirectory&) = delete; + CiffDirectory& operator=(const CiffDirectory&) = delete; + //! @name Manipulators //@{ // Default assignment operator is fine @@ -522,6 +525,7 @@ struct CrwMapping { */ class CrwMap { public: + ~CrwMap() = delete; //! @name Not implemented //@{ CrwMap(const CrwMap&) = delete; diff --git a/src/makernote_int.hpp b/src/makernote_int.hpp index 28b25f0f56..5a8880fac9 100644 --- a/src/makernote_int.hpp +++ b/src/makernote_int.hpp @@ -81,8 +81,10 @@ class TiffMnCreator { */ static TiffComponent* create(uint16_t tag, IfdId group, IfdId mnGroup); + ~TiffMnCreator() = default; //! Prevent destruction (needed if used as a policy class) - ~TiffMnCreator() = delete; + TiffMnCreator(const TiffComponent&) = delete; + TiffMnCreator& operator=(const TiffComponent&) = delete; private: static const TiffMnRegistry registry_[]; // Date: Sat, 21 May 2022 16:43:19 -0700 Subject: [PATCH 3/3] 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 ef6f842ed5..c13e0c5d2b 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -349,7 +349,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) { @@ -753,7 +753,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 d5dc88c795..903391bae1 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) { @@ -388,7 +388,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; } } @@ -403,7 +403,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; } @@ -825,7 +825,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(); @@ -935,7 +935,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 @@ -1065,7 +1066,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*/, @@ -1073,7 +1075,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 @@ -1196,7 +1199,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); @@ -1484,7 +1488,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 << " "; }