From f787a4c2acda86016ae58c5c9dbb6d88b86cac30 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 20 Jun 2022 23:36:06 -0700 Subject: [PATCH 01/13] clang-tidy: add missing override Signed-off-by: Rosen Penev --- include/exiv2/webpimage.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index 317e5986..dd59142f 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -54,7 +54,7 @@ class EXIV2API WebPImage : public Image { [[nodiscard]] std::string mimeType() const override; //@} - ~WebPImage() = default; + ~WebPImage() override = default; //! Copy constructor WebPImage(const WebPImage&) = delete; //! Assignment operator From c2be02145d88ba9733bbd50b1a739cbfa4ccfa7f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 20 Jun 2022 23:39:15 -0700 Subject: [PATCH 02/13] clang-tidy: use C++ casts Signed-off-by: Rosen Penev --- app/exiv2.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index a81f2123..c4f7dd19 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -742,12 +742,12 @@ int Params::evalDelete(const std::string& optArg) { switch (action_) { case Action::none: action_ = Action::erase; - target_ = CommonTarget(0); + target_ = static_cast(0); // fallthrough case Action::erase: { const auto rc = parseCommonTargets(optArg, "erase"); if (rc > 0) { - target_ |= CommonTarget(rc); + target_ |= static_cast(rc); return 0; } else { return 1; @@ -764,12 +764,12 @@ int Params::evalExtract(const std::string& optArg) { case Action::none: case Action::modify: action_ = Action::extract; - target_ = CommonTarget(0); + target_ = static_cast(0); // fallthrough case Action::extract: { const auto rc = parseCommonTargets(optArg, "extract"); if (rc > 0) { - target_ |= CommonTarget(rc); + target_ |= static_cast(rc); return 0; } else { return 1; @@ -786,12 +786,12 @@ int Params::evalInsert(const std::string& optArg) { case Action::none: case Action::modify: action_ = Action::insert; - target_ = CommonTarget(0); + target_ = static_cast(0); // fallthrough case Action::insert: { const auto rc = parseCommonTargets(optArg, "insert"); if (rc > 0) { - target_ |= CommonTarget(rc); + target_ |= static_cast(rc); return 0; } else { return 1; @@ -1139,7 +1139,7 @@ void printUnrecognizedArgument(const char argc, const std::string& action) { int64_t parseCommonTargets(const std::string& optArg, const std::string& action) { int64_t rc = 0; - Params::CommonTarget target = Params::CommonTarget(0); + Params::CommonTarget target = static_cast(0); Params::CommonTarget all = Params::ctExif | Params::ctIptc | Params::ctComment | Params::ctXmp; Params::CommonTarget extra = Params::ctXmpSidecar | Params::ctExif | Params::ctIptc | Params::ctXmp; for (size_t i = 0; rc == 0 && i < optArg.size(); ++i) { @@ -1175,7 +1175,7 @@ int64_t parseCommonTargets(const std::string& optArg, const std::string& action) target |= extra; // -eX if (i > 0) { // -eXX or -iXX target |= Params::ctXmpRaw; - target = Params::CommonTarget(target & ~extra); // turn off those bits + target = static_cast(target & ~extra); // turn off those bits } break; @@ -1196,7 +1196,7 @@ int64_t parseCommonTargets(const std::string& optArg, const std::string& action) break; } } - return rc ? rc : int64_t(target); + return rc ? rc : static_cast(target); } int parsePreviewNumbers(Params::PreviewNumbers& previewNumbers, const std::string& optArg, int j) { From 84555f1ad51f5b6f9ac5da97831073d23351477b Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 20 Jun 2022 23:43:52 -0700 Subject: [PATCH 03/13] clang-tidy: no else after return Signed-off-by: Rosen Penev --- app/exiv2.cpp | 9 +++------ src/types.cpp | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index c4f7dd19..cef78b55 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -749,9 +749,8 @@ int Params::evalDelete(const std::string& optArg) { if (rc > 0) { target_ |= static_cast(rc); return 0; - } else { - return 1; } + return 1; } default: std::cerr << progname() << ": " << _("Option -d is not compatible with a previous option\n"); @@ -771,9 +770,8 @@ int Params::evalExtract(const std::string& optArg) { if (rc > 0) { target_ |= static_cast(rc); return 0; - } else { - return 1; } + return 1; } default: std::cerr << progname() << ": " << _("Option -e is not compatible with a previous option\n"); @@ -793,9 +791,8 @@ int Params::evalInsert(const std::string& optArg) { if (rc > 0) { target_ |= static_cast(rc); return 0; - } else { - return 1; } + return 1; } default: std::cerr << progname() << ": " << _("Option -i is not compatible with a previous option\n"); diff --git a/src/types.cpp b/src/types.cpp index 1ec865e4..ff6bc48b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -178,7 +178,8 @@ byte* Exiv2::DataBuf::data(size_t offset) { const byte* Exiv2::DataBuf::c_data(size_t offset) const { if (pData_.empty()) { return nullptr; - } else if (offset >= pData_.size()) { + } + if (offset >= pData_.size()) { throw std::out_of_range("Overflow in Exiv2::DataBuf::c_data"); } return &pData_[offset]; From 5ca0acd1299c013222251e58f98eea781858356e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 20 Jun 2022 23:49:43 -0700 Subject: [PATCH 04/13] clang-tidy: some llvm- warnings Signed-off-by: Rosen Penev --- include/exiv2/bmffimage.hpp | 2 +- include/exiv2/properties.hpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/exiv2/bmffimage.hpp b/include/exiv2/bmffimage.hpp index d7963837..7fc29479 100644 --- a/include/exiv2/bmffimage.hpp +++ b/include/exiv2/bmffimage.hpp @@ -14,7 +14,7 @@ // namespace extensions namespace Exiv2 { EXIV2API bool enableBMFF(bool enable = true); -} +} // namespace Exiv2 #ifdef EXV_ENABLE_BMFF namespace Exiv2 { diff --git a/include/exiv2/properties.hpp b/include/exiv2/properties.hpp index 36dc8179..295306fb 100644 --- a/include/exiv2/properties.hpp +++ b/include/exiv2/properties.hpp @@ -8,6 +8,7 @@ // included header files #include + #include "datasets.hpp" // ***************************************************************************** From c74ae5aa00a6ce576daab0797a5d389bd50c896e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 20 Jun 2022 23:55:56 -0700 Subject: [PATCH 05/13] clang-tidy: remove const char operator It morphs into std::string anyway. Signed-off-by: Rosen Penev --- include/exiv2/xmp_exiv2.hpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/exiv2/xmp_exiv2.hpp b/include/exiv2/xmp_exiv2.hpp index ec3d02c6..e8a0495c 100644 --- a/include/exiv2/xmp_exiv2.hpp +++ b/include/exiv2/xmp_exiv2.hpp @@ -58,11 +58,6 @@ class EXIV2API Xmpdatum : public Metadatum { Calls setValue(const std::string&). */ Xmpdatum& operator=(const std::string& value); - /*! - @brief Assign const char* \em value to the %Xmpdatum. - Calls operator=(const std::string&). - */ - Xmpdatum& operator=(const char* value); /*! @brief Assign a boolean \em value to the %Xmpdatum. Translates the value to a string "true" or "false". @@ -404,10 +399,6 @@ class EXIV2API XmpParser { // ***************************************************************************** // free functions, template and inline definitions -inline Xmpdatum& Xmpdatum::operator=(const char* value) { - return Xmpdatum::operator=(std::string(value)); -} - inline Xmpdatum& Xmpdatum::operator=(const bool& value) { return operator=(value ? "True" : "False"); } From e2ee1338f500b30d931de8f8a105e8bf02231e88 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 21 Jun 2022 00:06:34 -0700 Subject: [PATCH 06/13] pass bool by value No sense in passing by reference Signed-off-by: Rosen Penev --- include/exiv2/xmp_exiv2.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/exiv2/xmp_exiv2.hpp b/include/exiv2/xmp_exiv2.hpp index e8a0495c..064a46d7 100644 --- a/include/exiv2/xmp_exiv2.hpp +++ b/include/exiv2/xmp_exiv2.hpp @@ -62,7 +62,7 @@ class EXIV2API Xmpdatum : public Metadatum { @brief Assign a boolean \em value to the %Xmpdatum. Translates the value to a string "true" or "false". */ - Xmpdatum& operator=(const bool& value); + Xmpdatum& operator=(bool value); /*! @brief Assign a \em value of any type with an output operator to the %Xmpdatum. Calls operator=(const std::string&). @@ -399,7 +399,7 @@ class EXIV2API XmpParser { // ***************************************************************************** // free functions, template and inline definitions -inline Xmpdatum& Xmpdatum::operator=(const bool& value) { +inline Xmpdatum& Xmpdatum::operator=(bool value) { return operator=(value ? "True" : "False"); } From fc1a39848853ff2d5c8e3046c508a498464fb7b4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 21 Jun 2022 00:08:28 -0700 Subject: [PATCH 07/13] clang-tidy: remove const It doesn't do what it's supposed to here. Found with misc-misplaced-const Signed-off-by: Rosen Penev --- src/xmp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmp.cpp b/src/xmp.cpp index cb4f422d..ed54b340 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -53,7 +53,7 @@ class XMLValidator { // error out if the depth exceeds this limit. static const size_t max_recursion_limit_ = 1000; - const XML_Parser parser_; + XML_Parser parser_; public: // Runs an XML parser on `buf`. Throws an exception if the XML is invalid. From 9f989e42285e36739481a7a5e6b3355a2aaa97d8 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 2 Jul 2022 12:28:45 -0700 Subject: [PATCH 08/13] clang-tidy: use auto Signed-off-by: Rosen Penev --- app/exiv2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index cef78b55..1ca9846d 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -1136,7 +1136,7 @@ void printUnrecognizedArgument(const char argc, const std::string& action) { int64_t parseCommonTargets(const std::string& optArg, const std::string& action) { int64_t rc = 0; - Params::CommonTarget target = static_cast(0); + auto target = static_cast(0); Params::CommonTarget all = Params::ctExif | Params::ctIptc | Params::ctComment | Params::ctXmp; Params::CommonTarget extra = Params::ctXmpSidecar | Params::ctExif | Params::ctIptc | Params::ctXmp; for (size_t i = 0; rc == 0 && i < optArg.size(); ++i) { From 3e37c17f5169a400d41790d0145e896d548ca25d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 2 Jul 2022 12:30:46 -0700 Subject: [PATCH 09/13] clang-tidy: missing override Signed-off-by: Rosen Penev --- app/exiv2app.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/exiv2app.hpp b/app/exiv2app.hpp index cae67770..5c278f9a 100644 --- a/app/exiv2app.hpp +++ b/app/exiv2app.hpp @@ -122,7 +122,7 @@ class Params : public Util::Getopt { static Params& instance(); //! Prevent copy-construction: not implemented. - ~Params() = default; + ~Params() override = default; Params(const Params&) = delete; Params& operator=(const Params&) = delete; From 7f9242afc6105c0a422ed3d2b50823f4d4e4cd94 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 2 Jul 2022 12:34:29 -0700 Subject: [PATCH 10/13] clang-tidy: replace + with append() Silences clang-tidy performance warning Signed-off-by: Rosen Penev --- src/nikonmn_int.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index 15236e6f..047beba9 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -3233,9 +3233,9 @@ std::ostream& Nikon3MakerNote::print0x009e(std::ostream& os, const Value& value, std::string d = s.empty() ? "" : "; "; const TagDetails* td = find(nikonRetouchHistory, l); if (td) { - s = std::string(exvGettext(td->label_)) + d + s; + s = std::string(exvGettext(td->label_)).append(d).append(s); } else { - s = std::string(_("Unknown")) + std::string(" (") + toString(l) + std::string(")") + d + s; + s = std::string(_("Unknown")).append(" (").append(toString(l)).append(")").append(d).append(s); } } return os << s; From c0083d6788254c58dd7dfcaed7667fbab5312da1 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 2 Jul 2022 12:38:32 -0700 Subject: [PATCH 11/13] clang-tidy: fix mismatching declaration variable Signed-off-by: Rosen Penev --- src/utils.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.hpp b/src/utils.hpp index 1e16648d..c385b07d 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -14,7 +14,7 @@ constexpr bool startsWith(std::string_view s, std::string_view start) { std::string upper(const std::string& str); /// @brief Returns the lowercase version of \b str -std::string lower(const std::string& str); +std::string lower(const std::string& a); } // namespace Exiv2::Internal From 5be42f132cf9f2204d69e414f88229874a845881 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 2 Jul 2022 13:20:23 -0700 Subject: [PATCH 12/13] try to fix some fanalyzer warnings Signed-off-by: Rosen Penev --- src/convert.cpp | 2 +- src/pngchunk_int.cpp | 18 ++++++------------ src/tags.cpp | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/convert.cpp b/src/convert.cpp index de9aafac..2ea74b31 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -1284,7 +1284,7 @@ std::string Converter::computeExifDigest(bool tiff) { } #else std::string Converter::computeExifDigest(bool) { - return std::string(""); + return {}; } #endif diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 53ae8093..c202a6d5 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -318,31 +318,25 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize, } // PngChunk::parseChunkContent std::string PngChunk::makeMetadataChunk(const std::string& metadata, MetadataId type) { - std::string chunk; std::string rawProfile; switch (type) { case mdComment: - chunk = makeUtf8TxtChunk("Description", metadata, true); - break; + return makeUtf8TxtChunk("Description", metadata, true); case mdExif: rawProfile = writeRawProfile(metadata, "exif"); - chunk = makeAsciiTxtChunk("Raw profile type exif", rawProfile, true); - break; + return makeAsciiTxtChunk("Raw profile type exif", rawProfile, true); case mdIptc: rawProfile = writeRawProfile(metadata, "iptc"); - chunk = makeAsciiTxtChunk("Raw profile type iptc", rawProfile, true); - break; + return makeAsciiTxtChunk("Raw profile type iptc", rawProfile, true); case mdXmp: - chunk = makeUtf8TxtChunk("XML:com.adobe.xmp", metadata, false); - break; + return makeUtf8TxtChunk("XML:com.adobe.xmp", metadata, false); case mdIccProfile: - break; case mdNone: - break; + return {}; } - return chunk; + return {}; } // PngChunk::makeMetadataChunk diff --git a/src/tags.cpp b/src/tags.cpp index f084dd9d..13c231c0 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -302,7 +302,7 @@ std::string ExifKey::tagLabel() const { std::string ExifKey::tagDesc() const { if (!p_->tagInfo_ || p_->tagInfo_->tag_ == 0xffff) - return ""; + return {}; return _(p_->tagInfo_->desc_); } From 75753007321cc5208e44b3cd1c5d82fe3e902854 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 4 Jul 2022 21:45:06 -0700 Subject: [PATCH 13/13] clang: remove pointless ; at the end of function Signed-off-by: Rosen Penev --- include/exiv2/xmp_exiv2.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/exiv2/xmp_exiv2.hpp b/include/exiv2/xmp_exiv2.hpp index 064a46d7..f7e78a7c 100644 --- a/include/exiv2/xmp_exiv2.hpp +++ b/include/exiv2/xmp_exiv2.hpp @@ -222,23 +222,23 @@ class EXIV2API XmpData { //! are we to use the packet? [[nodiscard]] bool usePacket() const { return usePacket_; - }; + } //! set usePacket_ bool usePacket(bool b) { bool r = usePacket_; usePacket_ = b; return r; - }; + } //! setPacket void setPacket(std::string xmpPacket) { xmpPacket_ = std::move(xmpPacket); usePacket(false); - }; + } // ! getPacket [[nodiscard]] const std::string& xmpPacket() const { return xmpPacket_; - }; + } //@}