From 0d971e98e4d71f3df9f8ec96c9a82d95b15b79af Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 12:41:22 -0700 Subject: [PATCH 1/9] remove some unique_ptrs They're not really used as pointers. Signed-off-by: Rosen Penev --- src/crwimage.cpp | 6 +++--- src/image.cpp | 6 ++---- src/jp2image.cpp | 6 +++--- src/jpgimage.cpp | 12 ++++++------ src/pgfimage.cpp | 6 +++--- src/pngimage.cpp | 6 +++--- src/psdimage.cpp | 6 +++--- src/tiffcomposite_int.cpp | 3 +-- src/tiffimage_int.cpp | 8 ++++---- src/webpimage.cpp | 6 +++--- src/xmpsidecar.cpp | 8 ++++---- 11 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/crwimage.cpp b/src/crwimage.cpp index ff217c7a32..d9686ea42e 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -92,10 +92,10 @@ void CrwImage::writeMetadata() { CrwParser::encode(blob, buf.c_data(), buf.size(), this); // Write new buffer to file - auto tempIo = std::make_unique(); - tempIo->write((!blob.empty() ? &blob[0] : nullptr), blob.size()); + MemIo tempIo; + tempIo.write((!blob.empty() ? &blob[0] : nullptr), blob.size()); io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } // CrwImage::writeMetadata diff --git a/src/image.cpp b/src/image.cpp index 30c75d9c85..052b8df828 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -791,8 +791,7 @@ Image::UniquePtr ImageFactory::open(const std::string& path, bool useCurl) { } Image::UniquePtr ImageFactory::open(const byte* data, size_t size) { - auto io = std::make_unique(data, size); - auto image = open(std::move(io)); // may throw + auto image = open(std::make_unique(data, size)); // may throw if (!image) throw Error(ErrorCode::kerMemoryContainsUnknownImageType); return image; @@ -826,8 +825,7 @@ Image::UniquePtr ImageFactory::create(ImageType type, const std::string& path) { } Image::UniquePtr ImageFactory::create(ImageType type) { - auto io = std::make_unique(); - auto image = create(type, std::move(io)); + auto image = create(type, std::make_unique()); if (!image) throw Error(ErrorCode::kerUnsupportedImageType, static_cast(type)); return image; diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 189ed2ea9c..84ab1dbc1d 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -585,11 +585,11 @@ void Jp2Image::writeMetadata() { throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - auto tempIo = std::make_unique(); + MemIo tempIo; - doWriteMetadata(*tempIo); // may throw + doWriteMetadata(tempIo); // may throw io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } // Jp2Image::writeMetadata diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 2f2ef8597e..9394753559 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -696,7 +696,7 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, in // exiv2 -pS E.jpg // binary copy io_ to a temporary file - auto tempIo = std::make_unique(); + MemIo tempIo; for (size_t i = 0; i < (count / 2) + 1; i++) { size_t start = pos[2 * i] + 2; // step JPG 2 byte marker if (start == 2) @@ -709,12 +709,12 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, in io_->seekOrThrow(start, BasicIo::beg, ErrorCode::kerFailedToReadImageData); DataBuf buf(length); io_->readOrThrow(buf.data(), buf.size(), ErrorCode::kerFailedToReadImageData); - tempIo->write(buf.c_data(), buf.size()); + tempIo.write(buf.c_data(), buf.size()); } } io_->seekOrThrow(0, BasicIo::beg, ErrorCode::kerFailedToReadImageData); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw io_->seekOrThrow(0, BasicIo::beg, ErrorCode::kerFailedToReadImageData); readMetadata(); } @@ -725,11 +725,11 @@ void JpegBase::writeMetadata() { throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - auto tempIo = std::make_unique(); + MemIo tempIo; - doWriteMetadata(*tempIo); // may throw + doWriteMetadata(tempIo); // may throw io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } DataBuf JpegBase::readNextSegment(byte marker) { diff --git a/src/pgfimage.cpp b/src/pgfimage.cpp index 3f5049d9c1..c41c85b3e1 100644 --- a/src/pgfimage.cpp +++ b/src/pgfimage.cpp @@ -120,11 +120,11 @@ void PgfImage::writeMetadata() { throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - auto tempIo = std::make_unique(); + MemIo tempIo; - doWriteMetadata(*tempIo); // may throw + doWriteMetadata(tempIo); // may throw io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } // PgfImage::writeMetadata diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 0743ab9cbb..e8adc4b8a2 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -480,11 +480,11 @@ void PngImage::writeMetadata() { throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - auto tempIo = std::make_unique(); + MemIo tempIo; - doWriteMetadata(*tempIo); // may throw + doWriteMetadata(tempIo); // may throw io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } // PngImage::writeMetadata diff --git a/src/psdimage.cpp b/src/psdimage.cpp index 4df8f88241..4274c43340 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -314,11 +314,11 @@ void PsdImage::writeMetadata() { throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - auto tempIo = std::make_unique(); + MemIo tempIo; - doWriteMetadata(*tempIo); // may throw + doWriteMetadata(tempIo); // may throw io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } // PsdImage::writeMetadata diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 841e97e24f..af3d6a5398 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -513,8 +513,7 @@ TiffComponent* TiffSubIfd::doAddPath(uint16_t tag, TiffPath& tiffPath, TiffCompo if (tiffPath.size() == 1 && object) { tc = addChild(std::move(object)); } else { - auto atc = std::make_unique(tpi1.tag(), tpi2.group()); - tc = addChild(std::move(atc)); + tc = addChild(std::make_unique(tpi1.tag(), tpi2.group())); } setCount(ifds_.size()); } diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 6101f8e15e..6a3224d789 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -1890,13 +1890,13 @@ WriteMethod TiffParserWorker::encode(BasicIo& io, const byte* pData, size_t size encoder.add(createdTree.get(), parsedTree.get(), root); // Write binary representation from the composite tree DataBuf header = pHeader->write(); - auto tempIo = std::make_unique(); - IoWrapper ioWrapper(*tempIo, header.c_data(), header.size(), pOffsetWriter); + 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); if (pOffsetWriter) - pOffsetWriter->writeOffsets(*tempIo); - io.transfer(*tempIo); // may throw + pOffsetWriter->writeOffsets(tempIo); + io.transfer(tempIo); // may throw #ifndef SUPPRESS_WARNINGS EXV_INFO << "Write strategy: Intrusive\n"; #endif diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 2018b5dce3..71fdd5991a 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -96,11 +96,11 @@ void WebPImage::writeMetadata() { throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); - auto tempIo = std::make_unique(); + MemIo tempIo; - doWriteMetadata(*tempIo); // may throw + doWriteMetadata(tempIo); // may throw io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } // WebPImage::writeMetadata void WebPImage::doWriteMetadata(BasicIo& outIo) { diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 388217195e..3b3698d65f 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -140,15 +140,15 @@ void XmpSidecar::writeMetadata() { if (xmpPacket_.substr(0, 5) != "(); + MemIo tempIo; // Write XMP packet - if (tempIo->write(reinterpret_cast(xmpPacket_.data()), xmpPacket_.size()) != xmpPacket_.size()) + if (tempIo.write(reinterpret_cast(xmpPacket_.data()), xmpPacket_.size()) != xmpPacket_.size()) throw Error(ErrorCode::kerImageWriteFailed); - if (tempIo->error()) + if (tempIo.error()) throw Error(ErrorCode::kerImageWriteFailed); io_->close(); - io_->transfer(*tempIo); // may throw + io_->transfer(tempIo); // may throw } } // XmpSidecar::writeMetadata From 1f05448d0ef37739fea46aad5d4ac307492ad553 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 13:05:54 -0700 Subject: [PATCH 2/9] clang-tidy: default member init Signed-off-by: Rosen Penev --- src/cr2header_int.cpp | 2 +- src/cr2header_int.hpp | 2 +- src/makernote_int.cpp | 14 +++++++------- src/makernote_int.hpp | 20 ++++++++++---------- src/orfimage_int.cpp | 2 +- src/orfimage_int.hpp | 4 ++-- src/tiffimage_int.hpp | 8 ++++---- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/cr2header_int.cpp b/src/cr2header_int.cpp index 7b2ffbd1df..a44ae3827c 100644 --- a/src/cr2header_int.cpp +++ b/src/cr2header_int.cpp @@ -3,7 +3,7 @@ #include "cr2header_int.hpp" namespace Exiv2::Internal { -Cr2Header::Cr2Header(ByteOrder byteOrder) : TiffHeaderBase(42, 16, byteOrder, 0x00000010), offset2_(0x00000000) { +Cr2Header::Cr2Header(ByteOrder byteOrder) : TiffHeaderBase(42, 16, byteOrder, 0x00000010) { } bool Cr2Header::read(const byte* pData, size_t size) { diff --git a/src/cr2header_int.hpp b/src/cr2header_int.hpp index 2e012029fc..e617e5e90b 100644 --- a/src/cr2header_int.hpp +++ b/src/cr2header_int.hpp @@ -49,7 +49,7 @@ class Cr2Header : public TiffHeaderBase { private: // DATA - uint32_t offset2_; //!< Bytes 12-15 from the header + uint32_t offset2_{0x00000000}; //!< Bytes 12-15 from the header static constexpr auto cr2sig_ = "CR\2\0"; //!< Signature for CR2 type TIFF }; // class Cr2Header diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index f8728c9f7d..d0da454bf8 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -274,7 +274,7 @@ size_t FujiMnHeader::sizeOfSignature() { return sizeof(signature_); } -FujiMnHeader::FujiMnHeader() : start_(0) { +FujiMnHeader::FujiMnHeader() { read(signature_, sizeOfSignature(), byteOrder_); } @@ -316,7 +316,7 @@ size_t Nikon2MnHeader::sizeOfSignature() { return sizeof(signature_); } -Nikon2MnHeader::Nikon2MnHeader() : start_(0) { +Nikon2MnHeader::Nikon2MnHeader() { read(signature_, sizeOfSignature(), invalidByteOrder); } @@ -351,7 +351,7 @@ size_t Nikon3MnHeader::sizeOfSignature() { return sizeof(signature_); } -Nikon3MnHeader::Nikon3MnHeader() : byteOrder_(invalidByteOrder), start_(sizeOfSignature()) { +Nikon3MnHeader::Nikon3MnHeader() : start_(sizeOfSignature()) { buf_.alloc(sizeOfSignature()); std::copy_n(signature_, buf_.size(), buf_.data()); } @@ -406,7 +406,7 @@ size_t PanasonicMnHeader::sizeOfSignature() { return sizeof(signature_); } -PanasonicMnHeader::PanasonicMnHeader() : start_(0) { +PanasonicMnHeader::PanasonicMnHeader() { read(signature_, sizeOfSignature(), invalidByteOrder); } @@ -527,7 +527,7 @@ size_t SigmaMnHeader::sizeOfSignature() { return sizeof(signature1_); } -SigmaMnHeader::SigmaMnHeader() : start_(0) { +SigmaMnHeader::SigmaMnHeader() { read(signature1_, sizeOfSignature(), invalidByteOrder); } @@ -561,7 +561,7 @@ size_t SonyMnHeader::sizeOfSignature() { return sizeof(signature_); } -SonyMnHeader::SonyMnHeader() : start_(0) { +SonyMnHeader::SonyMnHeader() { read(signature_, sizeOfSignature(), invalidByteOrder); } @@ -596,7 +596,7 @@ size_t Casio2MnHeader::sizeOfSignature() { return sizeof(signature_); } -Casio2MnHeader::Casio2MnHeader() : start_(0) { +Casio2MnHeader::Casio2MnHeader() { read(signature_, sizeOfSignature(), invalidByteOrder); } diff --git a/src/makernote_int.hpp b/src/makernote_int.hpp index ff1a16e805..930ef8b720 100644 --- a/src/makernote_int.hpp +++ b/src/makernote_int.hpp @@ -250,7 +250,7 @@ class FujiMnHeader : public MnHeader { DataBuf header_; //!< Data buffer for the makernote header static const byte signature_[]; //!< Fujifilm makernote header signature static const ByteOrder byteOrder_; //!< Byteorder for makernote (always II) - uint32_t start_; //!< Start of the mn IFD rel. to mn start + uint32_t start_{0}; //!< Start of the mn IFD rel. to mn start }; // class FujiMnHeader @@ -279,7 +279,7 @@ class Nikon2MnHeader : public MnHeader { private: DataBuf buf_; //!< Raw header data - size_t start_; //!< Start of the mn IFD rel. to mn start + size_t start_{0}; //!< Start of the mn IFD rel. to mn start static const byte signature_[]; //!< Nikon 2 makernote header signature }; // class Nikon2MnHeader @@ -311,10 +311,10 @@ class Nikon3MnHeader : public MnHeader { static size_t sizeOfSignature(); private: - DataBuf buf_; //!< Raw header data - ByteOrder byteOrder_; //!< Byteorder for makernote - size_t start_; //!< Start of the mn IFD rel. to mn start - static const byte signature_[]; //!< Nikon 3 makernote header signature + DataBuf buf_; //!< Raw header data + ByteOrder byteOrder_{invalidByteOrder}; //!< Byteorder for makernote + size_t start_; //!< Start of the mn IFD rel. to mn start + static const byte signature_[]; //!< Nikon 3 makernote header signature }; // class Nikon3MnHeader @@ -343,7 +343,7 @@ class PanasonicMnHeader : public MnHeader { private: DataBuf buf_; //!< Raw header data - size_t start_; //!< Start of the mn IFD rel. to mn start + size_t start_{0}; //!< Start of the mn IFD rel. to mn start static const byte signature_[]; //!< Panasonic makernote header signature }; // class PanasonicMnHeader @@ -453,7 +453,7 @@ class SigmaMnHeader : public MnHeader { private: DataBuf buf_; //!< Raw header data - size_t start_; //!< Start of the mn IFD rel. to mn start + size_t start_{0}; //!< Start of the mn IFD rel. to mn start static const byte signature1_[]; //!< Sigma makernote header signature 1 static const byte signature2_[]; //!< Sigma makernote header signature 2 @@ -484,7 +484,7 @@ class SonyMnHeader : public MnHeader { private: DataBuf buf_; //!< Raw header data - size_t start_; //!< Start of the mn IFD rel. to mn start + size_t start_{0}; //!< Start of the mn IFD rel. to mn start static const byte signature_[]; //!< Sony makernote header signature }; // class SonyMnHeader @@ -515,7 +515,7 @@ class Casio2MnHeader : public MnHeader { private: DataBuf buf_; //!< Raw header data - size_t start_; //!< Start of the mn IFD rel. to mn start + size_t start_{0}; //!< Start of the mn IFD rel. to mn start static const byte signature_[]; //!< Casio makernote header signature static const ByteOrder byteOrder_; //!< Byteorder for makernote (always big endian) diff --git a/src/orfimage_int.cpp b/src/orfimage_int.cpp index 2483db06a8..bc8ac78812 100644 --- a/src/orfimage_int.cpp +++ b/src/orfimage_int.cpp @@ -3,7 +3,7 @@ #include "orfimage_int.hpp" namespace Exiv2::Internal { -OrfHeader::OrfHeader(ByteOrder byteOrder) : TiffHeaderBase(0x4f52, 8, byteOrder, 0x00000008), sig_(0x4f52) { +OrfHeader::OrfHeader(ByteOrder byteOrder) : TiffHeaderBase(0x4f52, 8, byteOrder, 0x00000008) { } bool OrfHeader::read(const byte* pData, size_t size) { diff --git a/src/orfimage_int.hpp b/src/orfimage_int.hpp index 46d101f156..8dbd4355ad 100644 --- a/src/orfimage_int.hpp +++ b/src/orfimage_int.hpp @@ -37,8 +37,8 @@ class OrfHeader : public TiffHeaderBase { //@} private: // DATA - uint16_t sig_; //; From e654b2931c862cc7c90dcc281dda33f905e72f29 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 13:13:42 -0700 Subject: [PATCH 3/9] clang-tidy: replace throw() with noexcept Signed-off-by: Rosen Penev --- src/image_int.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/image_int.hpp b/src/image_int.hpp index bf74c490be..1a2fd7590f 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -62,7 +62,7 @@ std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& bi template struct binaryToStringHelper { - explicit binaryToStringHelper(const Slice myBuf) throw() : buf_(myBuf) { + explicit binaryToStringHelper(const Slice myBuf) noexcept : buf_(myBuf) { } friend std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& binToStr); @@ -95,7 +95,7 @@ struct binaryToStringHelper { * the stream throws neither. */ template -inline binaryToStringHelper binaryToString(const Slice sl) throw() { +inline binaryToStringHelper binaryToString(const Slice sl) noexcept { return binaryToStringHelper(sl); } From 49bf7e1387925356ff84b42e8f8859c000a473b2 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 13:16:58 -0700 Subject: [PATCH 4/9] clang-tidy: use delete Signed-off-by: Rosen Penev --- src/tiffcomposite_int.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index b9b65f4a47..e4731d1135 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -1213,7 +1213,6 @@ class TiffIfdMakernote : public TiffComponent { [[nodiscard]] size_t doSizeImage() const override; //@} - private: /*! @name NOT implemented @@ -1223,11 +1222,12 @@ class TiffIfdMakernote : public TiffComponent { */ //@{ //! Copy constructor. - TiffIfdMakernote(const TiffIfdMakernote& rhs); + TiffIfdMakernote(const TiffIfdMakernote&) = delete; //! Assignment operator. - TiffIfdMakernote& operator=(const TiffIfdMakernote& rhs); + TiffIfdMakernote& operator=(const TiffIfdMakernote&) = delete; //@} + private: // DATA MnHeader* pHeader_; //!< Makernote header TiffDirectory ifd_; //!< Makernote IFD From ae66ecec0d0243b7b772b5477601e68a063b208f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 13:19:13 -0700 Subject: [PATCH 5/9] clang-tidy: use nullptr Signed-off-by: Rosen Penev --- src/tiffcomposite_int.hpp | 2 +- src/xmp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index e4731d1135..b33ba33e86 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -1547,7 +1547,7 @@ TiffComponent::UniquePtr newTiffBinaryArray0(uint16_t tag, IfdId group) { //! Function to create and initialize a new simple binary array entry template TiffComponent::UniquePtr newTiffBinaryArray1(uint16_t tag, IfdId group) { - return TiffComponent::UniquePtr(new TiffBinaryArray(tag, group, arrayCfg, 0, 0)); + return TiffComponent::UniquePtr(new TiffBinaryArray(tag, group, arrayCfg, nullptr, 0)); } //! Function to create and initialize a new complex binary array entry diff --git a/src/xmp.cpp b/src/xmp.cpp index 5355f578e6..cb4f422db6 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -68,7 +68,7 @@ class XMLValidator { private: // Private constructor, because this class is only constructed by // the (static) check method. - XMLValidator() : parser_(XML_ParserCreateNS(0, '@')) { + XMLValidator() : parser_(XML_ParserCreateNS(nullptr, '@')) { if (!parser_) { throw Error(ErrorCode::kerXMPToolkitError, "Could not create expat parser"); } From a20ace20fc4df8849b35744cbb71c1d117a11d04 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 13:25:55 -0700 Subject: [PATCH 6/9] clang-tidy: manual clang-tidy fixes clang-tidy has issues applying these. Signed-off-by: Rosen Penev --- include/exiv2/bmffimage.hpp | 2 +- include/exiv2/slice.hpp | 34 +++++++++++++++++----------------- include/exiv2/value.hpp | 3 +-- src/crwimage_int.hpp | 10 ++++------ src/image_int.hpp | 2 +- src/pngchunk_int.hpp | 1 - src/tiffcomposite_int.hpp | 28 ++++++++++++++-------------- src/tiffimage_int.hpp | 7 +++---- 8 files changed, 41 insertions(+), 46 deletions(-) diff --git a/include/exiv2/bmffimage.hpp b/include/exiv2/bmffimage.hpp index 94984a9e13..26e9f93b28 100644 --- a/include/exiv2/bmffimage.hpp +++ b/include/exiv2/bmffimage.hpp @@ -123,7 +123,7 @@ class EXIV2API BmffImage : public Image { @warning This function should only be called by readMetadata() */ long boxHandler(std::ostream& out, Exiv2::PrintStructureOption option, const long pbox_end, int depth); - [[nodiscard]] std::string indent(int i) const { + [[nodiscard]] static std::string indent(int i) { return std::string(2 * i, ' '); } diff --git a/include/exiv2/slice.hpp b/include/exiv2/slice.hpp index 2068339ff2..5cca6364e0 100644 --- a/include/exiv2/slice.hpp +++ b/include/exiv2/slice.hpp @@ -109,14 +109,14 @@ struct ConstSliceBase : SliceBase { /*! * Obtain a constant iterator to the first element in the slice. */ - const_iterator cbegin() const noexcept { + [[nodiscard]] const_iterator cbegin() const noexcept { return storage_.unsafeGetIteratorAt(begin_); } /*! * Obtain a constant iterator to the first beyond the slice. */ - const_iterator cend() const noexcept { + [[nodiscard]] const_iterator cend() const noexcept { return storage_.unsafeGetIteratorAt(end_); } @@ -129,7 +129,7 @@ struct ConstSliceBase : SliceBase { * mutable_slice_base. */ template - slice_type subSlice(size_t begin, size_t end) const { + [[nodiscard]] slice_type subSlice(size_t begin, size_t end) const { this->rangeCheck(begin); // end == size() is a legal value, since end is the first // element beyond the slice @@ -219,8 +219,8 @@ struct MutableSliceBase : public ConstSliceBase { * the appropriate `slice` and call its `subSlice() const`, * which returns the correct type. */ - ConstSliceBase to_const_base() const noexcept { - return ConstSliceBase(this->storage_.data_, this->begin_, this->end_); + [[nodiscard]] ConstSliceBase to_const_base() const noexcept { + return {this->storage_.data_, this->begin_, this->end_}; } using base_type = ConstSliceBase; @@ -281,11 +281,11 @@ struct ContainerStorage { * * @throw whatever container::at() throws */ - const value_type& unsafeAt(size_t index) const { + [[nodiscard]] const value_type& unsafeAt(size_t index) const { return data_.at(index); } - value_type& unsafeAt(size_t index) { + [[nodiscard]] value_type& unsafeAt(size_t index) { return data_.at(index); } @@ -295,19 +295,19 @@ struct ContainerStorage { * * @throw whatever container::begin() and std::advance() throw */ - iterator unsafeGetIteratorAt(size_t index) { + [[nodiscard]] iterator unsafeGetIteratorAt(size_t index) { // we are screwed if the container got changed => try to catch it assert(index <= data_.size()); - iterator it = data_.begin(); + auto it = data_.begin(); std::advance(it, index); return it; } - const_iterator unsafeGetIteratorAt(size_t index) const { + [[nodiscard]] const_iterator unsafeGetIteratorAt(size_t index) const { assert(index <= data_.size()); - const_iterator it = data_.begin(); + auto it = data_.begin(); std::advance(it, index); return it; } @@ -346,11 +346,11 @@ struct PtrSliceStorage { * * @throw nothing */ - value_type& unsafeAt(size_t index) noexcept { + [[nodiscard]] value_type& unsafeAt(size_t index) noexcept { return data_[index]; } - const value_type& unsafeAt(size_t index) const noexcept { + [[nodiscard]] const value_type& unsafeAt(size_t index) const noexcept { return data_[index]; } @@ -360,11 +360,11 @@ struct PtrSliceStorage { * * @throw nothing */ - iterator unsafeGetIteratorAt(size_t index) noexcept { + [[nodiscard]] iterator unsafeGetIteratorAt(size_t index) noexcept { return data_ + index; } - const_iterator unsafeGetIteratorAt(size_t index) const noexcept { + [[nodiscard]] const_iterator unsafeGetIteratorAt(size_t index) const noexcept { return data_ + index; } @@ -462,7 +462,7 @@ struct Slice : public Internal::MutableSliceBase subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return this->to_const_base().template subSlice>(begin, end); } }; @@ -534,7 +534,7 @@ struct Slice : public Internal::MutableSliceBase::template subSlice>(begin, end); } - Slice subSlice(size_t begin, size_t end) const { + [[nodiscard]] Slice subSlice(size_t begin, size_t end) const { return this->to_const_base().template subSlice>(begin, end); } }; diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index d7081a0cc1..df4742c54a 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -1251,9 +1251,8 @@ class ValueType : public Value { if (static_cast(std::numeric_limits::min()) <= v && v <= static_cast(std::numeric_limits::max())) { return static_cast(std::round(v)); - } else { - return 0; } + return 0; } //! Utility for toInt64, toUint32, etc. diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 621ad74c9a..4c09abf829 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -371,13 +371,12 @@ class CiffDirectory : public CiffComponent { void doPrint(std::ostream& os, ByteOrder byteOrder, const std::string& prefix) const override; //! See base class comment. A directory is empty if it has no components. - bool doEmpty() const override; + [[nodiscard]] bool doEmpty() const override; // See base class comment [[nodiscard]] CiffComponent* doFindComponent(uint16_t crwTagId, uint16_t crwDir) const override; //@} - private: // DATA Components components_; //!< List of components in this dir UniquePtr m_; // used by recursive doAdd @@ -495,14 +494,14 @@ struct CrwMapping { //@{ //! Default constructor CrwMapping(uint16_t crwTagId, uint16_t crwDir, uint32_t size, uint16_t tag, Internal::IfdId ifdId, - const CrwDecodeFct& toExif, const CrwEncodeFct& fromExif) : + CrwDecodeFct toExif, CrwEncodeFct fromExif) : crwTagId_(crwTagId), crwDir_(crwDir), size_(size), tag_(tag), ifdId_(ifdId), - toExif_(toExif), - fromExif_(fromExif) { + toExif_(std::move(toExif)), + fromExif_(std::move(fromExif)) { } //@} @@ -633,7 +632,6 @@ class CrwMap { //! Encode the thumbnail image static void encode0x2008(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead); - private: // DATA static const CrwMapping crwMapping_[]; //!< Metadata conversion table static const CrwSubDir crwSubDir_[]; //!< Ciff directory hierarchy diff --git a/src/image_int.hpp b/src/image_int.hpp index 1a2fd7590f..0bf2a8b646 100644 --- a/src/image_int.hpp +++ b/src/image_int.hpp @@ -48,7 +48,7 @@ struct binaryToStringHelper; template std::ostream& operator<<(std::ostream& stream, const binaryToStringHelper& binToStr) { for (size_t i = 0; i < binToStr.buf_.size(); ++i) { - int c = static_cast(binToStr.buf_.at(i)); + auto c = static_cast(binToStr.buf_.at(i)); const bool bTrailingNull = c == 0 && i == binToStr.buf_.size() - 1; if (!bTrailingNull) { if (c < ' ' || c >= 127) { diff --git a/src/pngchunk_int.hpp b/src/pngchunk_int.hpp index d41c68fb24..1553758e47 100644 --- a/src/pngchunk_int.hpp +++ b/src/pngchunk_int.hpp @@ -25,7 +25,6 @@ class PngChunk { */ enum TxtChunkType { tEXt_Chunk = 0, zTXt_Chunk = 1, iTXt_Chunk = 2 }; - public: /*! @brief Decode PNG IHDR chunk data from a data buffer \em data and return image size to \em outWidth and \em outHeight. diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index b33ba33e86..8f2003ef0f 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -1101,6 +1101,20 @@ class TiffIfdMakernote : public TiffComponent { ~TiffIfdMakernote() override; //@} + /*! + @name NOT implemented + + Implementing the copy constructor and assignment operator will require + cloning the header, i.e., clone() functionality on the MnHeader + hierarchy. + */ + //@{ + //! Copy constructor. + TiffIfdMakernote(const TiffIfdMakernote&) = delete; + //! Assignment operator. + TiffIfdMakernote& operator=(const TiffIfdMakernote&) = delete; + //@} + //! @name Manipulators //@{ /*! @@ -1213,20 +1227,6 @@ class TiffIfdMakernote : public TiffComponent { [[nodiscard]] size_t doSizeImage() const override; //@} - /*! - @name NOT implemented - - Implementing the copy constructor and assignment operator will require - cloning the header, i.e., clone() functionality on the MnHeader - hierarchy. - */ - //@{ - //! Copy constructor. - TiffIfdMakernote(const TiffIfdMakernote&) = delete; - //! Assignment operator. - TiffIfdMakernote& operator=(const TiffIfdMakernote&) = delete; - //@} - private: // DATA MnHeader* pHeader_; //!< Makernote header diff --git a/src/tiffimage_int.hpp b/src/tiffimage_int.hpp index 6381512d13..4ca1d0f5a7 100644 --- a/src/tiffimage_int.hpp +++ b/src/tiffimage_int.hpp @@ -115,7 +115,7 @@ class TiffHeader : public TiffHeaderBase { //! @name Creators //@{ //! Default constructor - TiffHeader(ByteOrder byteOrder = littleEndian, uint32_t offset = 0x00000008, bool hasImageTags = true); + explicit TiffHeader(ByteOrder byteOrder = littleEndian, uint32_t offset = 0x00000008, bool hasImageTags = true); //! Destructor ~TiffHeader() override = default; //@} @@ -371,13 +371,12 @@ class OffsetWriter { //! Data structure for the offset list. struct OffsetData { //! Default constructor - OffsetData() { - } + OffsetData() = default; //! Constructor OffsetData(uint32_t origin, ByteOrder byteOrder) : origin_(origin), byteOrder_(byteOrder) { } // DATA - uint32_t origin_{0}; //!< Origin address + uint32_t origin_{}; //!< Origin address uint32_t target_{}; //!< Target address ByteOrder byteOrder_{littleEndian}; //!< Byte order to use to encode target address }; From b53ed72fd852a9f04d33781a924d572a79c978b0 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 14:18:43 -0700 Subject: [PATCH 7/9] clang-tidy: manual special functions Signed-off-by: Rosen Penev --- include/exiv2/basicio.hpp | 8 ++++++++ include/exiv2/bmpimage.hpp | 1 + include/exiv2/cr2image.hpp | 1 + include/exiv2/crwimage.hpp | 1 + include/exiv2/datasets.hpp | 3 ++- include/exiv2/epsimage.hpp | 1 + include/exiv2/gifimage.hpp | 1 + include/exiv2/image.hpp | 1 + include/exiv2/jp2image.hpp | 1 + include/exiv2/jpgimage.hpp | 3 +++ include/exiv2/metadatum.hpp | 3 ++- include/exiv2/mrwimage.hpp | 1 + include/exiv2/orfimage.hpp | 1 + include/exiv2/pgfimage.hpp | 1 + include/exiv2/pngimage.hpp | 1 + include/exiv2/properties.hpp | 1 + include/exiv2/psdimage.hpp | 1 + include/exiv2/rafimage.hpp | 1 + include/exiv2/rw2image.hpp | 1 + include/exiv2/tags.hpp | 1 + include/exiv2/tgaimage.hpp | 1 + include/exiv2/tiffimage.hpp | 1 + include/exiv2/types.hpp | 1 + include/exiv2/value.hpp | 2 ++ include/exiv2/xmpsidecar.hpp | 6 +++--- 25 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index ff5b9cb2db..869a8044e9 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -711,6 +711,9 @@ class EXIV2API XPathIo : public FileIo { ~XPathIo() override; //@} + XPathIo(const XPathIo&) = delete; + XPathIo& operator=(const XPathIo&) = delete; + //! @name Manipulators //@{ /*! @@ -751,6 +754,9 @@ class EXIV2API RemoteIo : public BasicIo { ~RemoteIo() override; //@} + RemoteIo(const RemoteIo&) = delete; + RemoteIo& operator=(const RemoteIo&) = delete; + //! @name Manipulators //@{ /*! @@ -920,6 +926,7 @@ class EXIV2API HttpIo : public RemoteIo { */ explicit HttpIo(const std::string& url, size_t blockSize = 1024); + ~HttpIo() override = default; // NOT IMPLEMENTED //! Copy constructor HttpIo(const HttpIo&) = delete; @@ -964,6 +971,7 @@ class EXIV2API CurlIo : public RemoteIo { */ size_t write(BasicIo& src) override; + ~CurlIo() override = default; // NOT IMPLEMENTED //! Copy constructor CurlIo(const CurlIo&) = delete; diff --git a/include/exiv2/bmpimage.hpp b/include/exiv2/bmpimage.hpp index b4078a5ea0..b37d41b210 100644 --- a/include/exiv2/bmpimage.hpp +++ b/include/exiv2/bmpimage.hpp @@ -26,6 +26,7 @@ namespace Exiv2 { */ class EXIV2API BmpImage : public Image { public: + ~BmpImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/cr2image.hpp b/include/exiv2/cr2image.hpp index 9277e1cfbf..a7fc663d88 100644 --- a/include/exiv2/cr2image.hpp +++ b/include/exiv2/cr2image.hpp @@ -71,6 +71,7 @@ class EXIV2API Cr2Image : public Image { [[nodiscard]] uint32_t pixelHeight() const override; //@} + ~Cr2Image() override = default; //! @name NOT implemented //@{ //! Copy constructor diff --git a/include/exiv2/crwimage.hpp b/include/exiv2/crwimage.hpp index 204fb79b84..5a44b82897 100644 --- a/include/exiv2/crwimage.hpp +++ b/include/exiv2/crwimage.hpp @@ -73,6 +73,7 @@ class EXIV2API CrwImage : public Image { [[nodiscard]] uint32_t pixelHeight() const override; //@} + ~CrwImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/datasets.hpp b/include/exiv2/datasets.hpp index 1863cf6b39..2d06e9e3ac 100644 --- a/include/exiv2/datasets.hpp +++ b/include/exiv2/datasets.hpp @@ -132,6 +132,7 @@ class EXIV2API IptcDataSets { static constexpr uint16_t Preview = 202; //@} + ~IptcDataSets() = delete; //! Prevent copy-construction: not implemented. IptcDataSets(const IptcDataSets&) = delete; //! Prevent assignment: not implemented. @@ -263,7 +264,7 @@ class EXIV2API IptcKey : public Key { IptcKey(uint16_t tag, uint16_t record); //! Copy constructor IptcKey(const IptcKey& rhs); - IptcKey& operator=(const IptcKey&) = delete; + IptcKey& operator=(const IptcKey&) = default; //! Destructor ~IptcKey() override = default; //@} diff --git a/include/exiv2/epsimage.hpp b/include/exiv2/epsimage.hpp index 9f6e4c4e73..a4b56b86f5 100644 --- a/include/exiv2/epsimage.hpp +++ b/include/exiv2/epsimage.hpp @@ -73,6 +73,7 @@ class EXIV2API EpsImage : public Image { [[nodiscard]] std::string mimeType() const override; //@} + ~EpsImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/gifimage.hpp b/include/exiv2/gifimage.hpp index 62e936e854..93bd422f3c 100644 --- a/include/exiv2/gifimage.hpp +++ b/include/exiv2/gifimage.hpp @@ -21,6 +21,7 @@ namespace Exiv2 { */ class EXIV2API GifImage : public Image { public: + ~GifImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index 4ed559057d..2a968fc325 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -656,6 +656,7 @@ class EXIV2API ImageFactory { //! @name Creators //@{ + ~ImageFactory() = delete; //! Prevent copy construction: not implemented. ImageFactory(const ImageFactory&) = delete; ImageFactory& operator=(const ImageFactory&) = delete; diff --git a/include/exiv2/jp2image.hpp b/include/exiv2/jp2image.hpp index 4fc79950d1..ae1a03e60c 100644 --- a/include/exiv2/jp2image.hpp +++ b/include/exiv2/jp2image.hpp @@ -64,6 +64,7 @@ class EXIV2API Jp2Image : public Image { [[nodiscard]] std::string mimeType() const override; //@} + ~Jp2Image() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/jpgimage.hpp b/include/exiv2/jpgimage.hpp index 168031cbd9..1fde606b2c 100644 --- a/include/exiv2/jpgimage.hpp +++ b/include/exiv2/jpgimage.hpp @@ -83,6 +83,7 @@ class EXIV2API JpegBase : public Image { void printStructure(std::ostream& out, PrintStructureOption option, int depth) override; //@} + ~JpegBase() override = default; //! @name NOT implemented //@{ //! Copy constructor @@ -264,6 +265,7 @@ class EXIV2API JpegImage : public JpegBase { [[nodiscard]] std::string mimeType() const override; //@} + ~JpegImage() override = default; // NOT Implemented //! Copy constructor JpegImage(const JpegImage&) = delete; @@ -323,6 +325,7 @@ class EXIV2API ExvImage : public JpegBase { [[nodiscard]] std::string mimeType() const override; //@} + ~ExvImage() override = default; // NOT Implemented //! Copy constructor ExvImage(const ExvImage&) = delete; diff --git a/include/exiv2/metadatum.hpp b/include/exiv2/metadatum.hpp index 6ffc2fd52c..d54b2ac309 100644 --- a/include/exiv2/metadatum.hpp +++ b/include/exiv2/metadatum.hpp @@ -30,10 +30,11 @@ class EXIV2API Key { //! @name Creators //@{ + Key() = default; //! Destructor virtual ~Key() = default; //@} - + Key(const Key&) = default; //! @name Accessors //@{ /*! diff --git a/include/exiv2/mrwimage.hpp b/include/exiv2/mrwimage.hpp index 229a96eb06..8abd8df80a 100644 --- a/include/exiv2/mrwimage.hpp +++ b/include/exiv2/mrwimage.hpp @@ -21,6 +21,7 @@ namespace Exiv2 { */ class EXIV2API MrwImage : public Image { public: + ~MrwImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/orfimage.hpp b/include/exiv2/orfimage.hpp index 4b960f6eec..89df53bf03 100644 --- a/include/exiv2/orfimage.hpp +++ b/include/exiv2/orfimage.hpp @@ -21,6 +21,7 @@ namespace Exiv2 { */ class EXIV2API OrfImage : public TiffImage { public: + ~OrfImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/pgfimage.hpp b/include/exiv2/pgfimage.hpp index f2cfcc79d9..f542820447 100644 --- a/include/exiv2/pgfimage.hpp +++ b/include/exiv2/pgfimage.hpp @@ -54,6 +54,7 @@ class EXIV2API PgfImage : public Image { } //@} + ~PgfImage() override = default; //! @name NOT implemented //@{ //! Copy constructor diff --git a/include/exiv2/pngimage.hpp b/include/exiv2/pngimage.hpp index fe9d836157..9c618785da 100644 --- a/include/exiv2/pngimage.hpp +++ b/include/exiv2/pngimage.hpp @@ -60,6 +60,7 @@ class EXIV2API PngImage : public Image { [[nodiscard]] std::string mimeType() const override; //@} + ~PngImage() override = default; //! @name NOT implemented //@{ //! Copy constructor diff --git a/include/exiv2/properties.hpp b/include/exiv2/properties.hpp index 0527d37f83..36dc81790f 100644 --- a/include/exiv2/properties.hpp +++ b/include/exiv2/properties.hpp @@ -71,6 +71,7 @@ class EXIV2API XmpProperties { static const XmpNsInfo* lookupNsRegistryUnsafe(const XmpNsInfo::Prefix& prefix); public: + ~XmpProperties() = delete; //! Prevent copy-construction: not implemented. XmpProperties(const XmpProperties&) = delete; //! Prevent assignment: not implemented. diff --git a/include/exiv2/psdimage.hpp b/include/exiv2/psdimage.hpp index 7aa7767c38..f058534355 100644 --- a/include/exiv2/psdimage.hpp +++ b/include/exiv2/psdimage.hpp @@ -20,6 +20,7 @@ namespace Exiv2 { */ class EXIV2API PsdImage : public Image { public: + ~PsdImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/rafimage.hpp b/include/exiv2/rafimage.hpp index 867355b3da..5edd9460f8 100644 --- a/include/exiv2/rafimage.hpp +++ b/include/exiv2/rafimage.hpp @@ -74,6 +74,7 @@ class EXIV2API RafImage : public Image { [[nodiscard]] uint32_t pixelHeight() const override; //@} + ~RafImage() override = default; //! @name NOT implemented //@{ //! Copy constructor diff --git a/include/exiv2/rw2image.hpp b/include/exiv2/rw2image.hpp index 0cfa59ee1a..63a940668f 100644 --- a/include/exiv2/rw2image.hpp +++ b/include/exiv2/rw2image.hpp @@ -72,6 +72,7 @@ class EXIV2API Rw2Image : public Image { [[nodiscard]] uint32_t pixelHeight() const override; //@} + ~Rw2Image() override = default; //! @name NOT implemented //@{ //! Copy constructor diff --git a/include/exiv2/tags.hpp b/include/exiv2/tags.hpp index f4a8f7ed79..d043cca41e 100644 --- a/include/exiv2/tags.hpp +++ b/include/exiv2/tags.hpp @@ -63,6 +63,7 @@ struct EXIV2API TagInfo { //! Access to Exif group and tag lists and misc. tag reference methods, implemented as a static class. class EXIV2API ExifTags { public: + ~ExifTags() = delete; //! Prevent copy-construction: not implemented. ExifTags(const ExifTags&) = delete; //! Prevent assignment: not implemented. diff --git a/include/exiv2/tgaimage.hpp b/include/exiv2/tgaimage.hpp index dc0220f363..232addf343 100644 --- a/include/exiv2/tgaimage.hpp +++ b/include/exiv2/tgaimage.hpp @@ -20,6 +20,7 @@ namespace Exiv2 { */ class EXIV2API TgaImage : public Image { public: + ~TgaImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/tiffimage.hpp b/include/exiv2/tiffimage.hpp index 87080df305..121c9021fc 100644 --- a/include/exiv2/tiffimage.hpp +++ b/include/exiv2/tiffimage.hpp @@ -68,6 +68,7 @@ class EXIV2API TiffImage : public Image { uint32_t pixelHeight() const override; //@} + ~TiffImage() override = default; //! @name NOT Implemented //@{ //! Copy constructor diff --git a/include/exiv2/types.hpp b/include/exiv2/types.hpp index d4ffeb2ec3..03419f0f95 100644 --- a/include/exiv2/types.hpp +++ b/include/exiv2/types.hpp @@ -121,6 +121,7 @@ class EXIV2API TypeInfo { TypeInfo(const TypeInfo&) = delete; //! Prevent assignment: not implemented. TypeInfo& operator=(const TypeInfo&) = delete; + ~TypeInfo() = delete; //! Return the name of the type, 0 if unknown. static const char* typeName(TypeId typeId); diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index df4742c54a..b22b47c930 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -38,6 +38,7 @@ class EXIV2API Value { //@{ //! Constructor, taking a type id to initialize the base class with explicit Value(TypeId typeId); + Value(const Value&) = default; //! Virtual destructor. virtual ~Value() = default; //@} @@ -489,6 +490,7 @@ class EXIV2API CommentValue : public StringValueBase { CharsetInfo(const CharsetInfo&) = delete; //! Prevent assignment: not implemented. CharsetInfo& operator=(const CharsetInfo&) = delete; + ~CharsetInfo() = delete; //! Return the name for a charset id static const char* name(CharsetId charsetId); diff --git a/include/exiv2/xmpsidecar.hpp b/include/exiv2/xmpsidecar.hpp index 653ee8d830..4a31939881 100644 --- a/include/exiv2/xmpsidecar.hpp +++ b/include/exiv2/xmpsidecar.hpp @@ -54,13 +54,13 @@ class EXIV2API XmpSidecar : public Image { [[nodiscard]] std::string mimeType() const override; //@} - private: //! @name NOT Implemented //@{ + ~XmpSidecar() override = default; //! Copy constructor - XmpSidecar(const XmpSidecar& rhs); + XmpSidecar(const XmpSidecar&) = delete; //! Assignment operator - XmpSidecar& operator=(const XmpSidecar& rhs); + XmpSidecar& operator=(const XmpSidecar&) = delete; //@} Exiv2::Dictionary dates_; From d789968e90bc202998c8d3a73403212641774a68 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 9 Apr 2022 18:20:20 -0700 Subject: [PATCH 8/9] replace malloc/free with new/delete Signed-off-by: Rosen Penev --- src/basicio.cpp | 2 +- src/properties.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index d5e0f836d7..8837f0bbbb 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -889,7 +889,7 @@ void XPathIo::ReadDataUri(const std::string& path) { throw Error(ErrorCode::kerErrorMessage, "No base64 data"); std::string data = path.substr(base64Pos + 7); - char* decodeData = new char[data.length()]; + auto decodeData = new char[data.length()]; auto size = base64decode(data.c_str(), decodeData, data.length()); if (size > 0) write((byte*)decodeData, size); diff --git a/src/properties.cpp b/src/properties.cpp index 6cbc73bef1..2462c8274e 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -4899,10 +4899,10 @@ void XmpProperties::registerNs(const std::string& ns, const std::string& prefix) // Using malloc/free for better system compatibility in case // users don't unregister their namespaces explicitly. XmpNsInfo xn; - auto c = static_cast(std::malloc(ns2.size() + 1)); + auto c = new char[ns2.size() + 1]; std::strcpy(c, ns2.c_str()); xn.ns_ = c; - c = static_cast(std::malloc(prefix.size() + 1)); + c = new char[prefix.size() + 1]; std::strcpy(c, prefix.c_str()); xn.prefix_ = c; xn.xmpPropertyInfo_ = nullptr; @@ -4918,8 +4918,8 @@ void XmpProperties::unregisterNs(const std::string& ns) { void XmpProperties::unregisterNsUnsafe(const std::string& ns) { auto i = nsRegistry_.find(ns); if (i != nsRegistry_.end()) { - std::free(const_cast(i->second.prefix_)); - std::free(const_cast(i->second.ns_)); + delete[] i->second.prefix_; + delete[] i->second.ns_; nsRegistry_.erase(i); } } From c997b09a81580dbe74b1e4085672510a401cec98 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 10 Apr 2022 01:11:19 -0700 Subject: [PATCH 9/9] algorithm conversions Signed-off-by: Rosen Penev --- src/makernote_int.cpp | 11 +++++++---- src/sonymn_int.cpp | 29 +++++++++++------------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index d0da454bf8..b8059883f3 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -887,10 +887,13 @@ constexpr auto nikonArrayIdx = std::array{ int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* const /*pRoot*/) { if (size < 4) return -1; - for (auto&& aix : nikonArrayIdx) - if (aix == NikonArrayIdx::Key(tag, reinterpret_cast(pData), size)) - return aix.idx_; - return -1; + + auto ix = NikonArrayIdx::Key(tag, reinterpret_cast(pData), size); + auto it = std::find_if(nikonArrayIdx.begin(), nikonArrayIdx.end(), [ix](auto&& aix) { return aix == ix; }); + if (it == nikonArrayIdx.end()) + return -1; + + return it->idx_; } DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* const pRoot) { diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index d7c3083bc8..b1be5749b1 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -855,12 +855,9 @@ std::ostream& SonyMakerNote::printSonyMisc3cShotNumberSincePowerUp(std::ostream& "DSC-RX100M4", "DSC-RX100M5", "DSC-WX220", "DSC-WX350", "DSC-WX500", }; - std::string model = pos->toString(); - for (auto& m : models) { - if (m == model) - return os << value.toInt64(); - } - + bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; }); + if (f) + return os << value.toInt64(); return os << N_("n/a"); } @@ -923,13 +920,11 @@ std::ostream& SonyMakerNote::printSonyMisc3cSonyImageHeight(std::ostream& os, co if (pos == metadata->end()) return os << "(" << value << ")"; - std::string model = pos->toString(); - // Models that do not support this tag - for (auto& m : {"ILCE-1", "ILCE-7SM3", "ILME-FX3"}) { - if (m == model) - return os << N_("n/a"); - } + const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"}; + bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; }); + if (f) + return os << N_("n/a"); const auto val = value.toInt64(); return val > 0 ? os << (8 * val) : os << N_("n/a"); @@ -944,13 +939,11 @@ std::ostream& SonyMakerNote::printSonyMisc3cModelReleaseYear(std::ostream& os, c if (pos == metadata->end()) return os << "(" << value << ")"; - std::string model = pos->toString(); - // Models that do not support this tag - for (auto& m : {"ILCE-1", "ILCE-7SM3", "ILME-FX3"}) { - if (m == model) - return os << N_("n/a"); - } + const auto models = std::array{"ILCE-1", "ILCE-7SM3", "ILME-FX3"}; + bool f = std::any_of(models.begin(), models.end(), [model = pos->toString()](auto&& m) { return m == model; }); + if (f) + return os << N_("n/a"); const auto val = value.toInt64(); if (val > 99)