From d7297a2c2c53d29b8df81d7d7cb889bc560369cc Mon Sep 17 00:00:00 2001 From: tbeu Date: Tue, 24 Oct 2017 23:02:01 +0200 Subject: [PATCH 1/7] Pass argument as constant reference --- src/convert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/convert.cpp b/src/convert.cpp index 0665b2bb..b2994177 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -1498,7 +1498,7 @@ namespace { typedef bool (*ConvFct)(std::string& str); struct ConvFctList { - bool operator==(std::pair fromTo) const + bool operator==(const std::pair &fromTo) const { return 0 == strcmp(from_, fromTo.first) && 0 == strcmp(to_, fromTo.second); } const char* from_; const char* to_; From fd64d53e4bd535efdca8d864b95068e7d9a206b2 Mon Sep 17 00:00:00 2001 From: tbeu Date: Tue, 24 Oct 2017 23:02:43 +0200 Subject: [PATCH 2/7] Remove superfluous variable declarations --- src/casiomn.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/casiomn.cpp b/src/casiomn.cpp index 3962234f..5c037d99 100644 --- a/src/casiomn.cpp +++ b/src/casiomn.cpp @@ -230,7 +230,6 @@ namespace Exiv2 { std::ostream& CasioMakerNote::print0x0015(std::ostream& os, const Value& value, const ExifData*) { // format is: "YYMM#00#00DDHH#00#00MM#00#00#00#00" or "YYMM#00#00DDHH#00#00MMSS#00#00#00" - std::string s; std::vector numbers; for(long i=0; i numbers; for(long i=0; i Date: Tue, 24 Oct 2017 23:14:26 +0200 Subject: [PATCH 3/7] Utilize const Value reference --- src/canonmn.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/canonmn.cpp b/src/canonmn.cpp index 5f53ba54..7da2ac30 100644 --- a/src/canonmn.cpp +++ b/src/canonmn.cpp @@ -1819,13 +1819,15 @@ namespace Exiv2 { ExifData::const_iterator pos = metadata->findKey(key); ltfl.focalLengthMin_ = 0.0; ltfl.focalLengthMax_ = 0.0; - if ( pos != metadata->end() - && pos->value().count() >= 3 - && pos->value().typeId() == unsignedShort) { - float fu = pos->value().toFloat(2); - if (fu != 0.0) { - ltfl.focalLengthMin_ = pos->value().toLong(1) / fu; - ltfl.focalLengthMax_ = pos->value().toLong(0) / fu; + if (pos != metadata->end()) { + const Value &value = pos->value(); + if ( value.count() >= 3 + && value.typeId() == unsignedShort) { + float fu = value.toFloat(2); + if (fu != 0.0) { + ltfl.focalLengthMin_ = value.toLong(1) / fu; + ltfl.focalLengthMax_ = value.toLong(0) / fu; + } } } } @@ -1938,12 +1940,12 @@ namespace Exiv2 { if ( value.typeId() != unsignedShort || value.count() == 0) return os << "(" << value << ")"; - // #1034 - const std::string undefined("undefined") ; - const std::string section ("canon"); - if ( Internal::readExiv2Config(section,value.toString(),undefined) != undefined ) { - return os << Internal::readExiv2Config(section,value.toString(),undefined); - } + // #1034 + const std::string undefined("undefined") ; + const std::string section ("canon"); + if ( Internal::readExiv2Config(section,value.toString(),undefined) != undefined ) { + return os << Internal::readExiv2Config(section,value.toString(),undefined); + } const LensIdFct* lif = find(lensIdFct, value.toLong()); if (!lif) { From 849f41677160af42d6390dd9780d0e7ff9754050 Mon Sep 17 00:00:00 2001 From: tbeu Date: Tue, 24 Oct 2017 23:23:11 +0200 Subject: [PATCH 4/7] Avoid self-assignment --- src/actions.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 33301f45..aefe1e85 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -249,12 +249,15 @@ namespace Action { case Params::pmRecursive: rc = printStructure(std::cout,Exiv2::kpsRecursive) ; break; case Params::pmXMP: - option = option == Exiv2::kpsNone ? Exiv2::kpsXMP : option; // drop - case Params::pmIccProfile:{ - option = option == Exiv2::kpsNone ? Exiv2::kpsIccProfile : option; - _setmode(_fileno(stdout),O_BINARY); - rc = printStructure(std::cout,option); - } break; + if (option == Exiv2::kpsNone) + option = Exiv2::kpsXMP; + // drop + case Params::pmIccProfile: + if (option == Exiv2::kpsNone) + option = Exiv2::kpsIccProfile; + _setmode(_fileno(stdout),O_BINARY); + rc = printStructure(std::cout,option); + break; } return rc; } From d1f73aa2374b0914a98a05c03c5e4f34964c9dbb Mon Sep 17 00:00:00 2001 From: tbeu Date: Wed, 25 Oct 2017 09:23:27 +0200 Subject: [PATCH 5/7] Make it floats --- src/canonmn.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/canonmn.cpp b/src/canonmn.cpp index 7da2ac30..245de1ad 100644 --- a/src/canonmn.cpp +++ b/src/canonmn.cpp @@ -1817,14 +1817,14 @@ namespace Exiv2 { { ExifKey key("Exif.CanonCs.Lens"); ExifData::const_iterator pos = metadata->findKey(key); - ltfl.focalLengthMin_ = 0.0; - ltfl.focalLengthMax_ = 0.0; + ltfl.focalLengthMin_ = 0.0f; + ltfl.focalLengthMax_ = 0.0f; if (pos != metadata->end()) { const Value &value = pos->value(); if ( value.count() >= 3 && value.typeId() == unsignedShort) { float fu = value.toFloat(2); - if (fu != 0.0) { + if (fu != 0.0f) { ltfl.focalLengthMin_ = value.toLong(1) / fu; ltfl.focalLengthMax_ = value.toLong(0) / fu; } From 22dbd632bb3cc03901c700747806f5c754f8da68 Mon Sep 17 00:00:00 2001 From: tbeu Date: Wed, 25 Oct 2017 09:28:14 +0200 Subject: [PATCH 6/7] Find single character --- src/xmp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmp.cpp b/src/xmp.cpp index 95a28a2e..dda96e90 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -478,7 +478,7 @@ namespace Exiv2 { out.erase(end_pos, out.end()); bool bURI = out.find("http://") != std::string::npos ; - bool bNS = out.find(":") != std::string::npos && !bURI; + bool bNS = out.find(':') != std::string::npos && !bURI; // pop trailing ':' on a namespace if ( bNS ) { From c0ea5f4fbadac4a35250c5ab560bd20472215450 Mon Sep 17 00:00:00 2001 From: tbeu Date: Wed, 25 Oct 2017 09:43:06 +0200 Subject: [PATCH 7/7] Rewrite the reallocation the C++ way * Fix handling of the return value of vsnprintf * In C++11 we could use buffer.data instead of &buffer[0] --- src/image.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 24bb3869..338720fc 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -994,26 +994,22 @@ namespace Exiv2 { std::string stringFormat(const char* format, ...) { std::string result; + std::vector buffer; + size_t need = std::strlen(format); // initial guess + int rc = -1; - int need = (int) std::strlen(format)*2; // initial guess - char* buffer = NULL; - int again = 4; - int rc = -1; + do { + 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); + va_end(args); // free the args + if ( rc > 0 ) + need = static_cast(rc); + } while ( buffer.size() <= need ); - while (rc < 0 && again--) { - if ( buffer ) delete[] buffer; - need *= 2 ; - buffer = new char[need]; - if ( buffer ) { - va_list args; // variable arg list - va_start(args, format); // args start after format - rc=vsnprintf(buffer,(unsigned int)need, format, args); - va_end(args); // free the args - } - } - - if ( rc > 0 ) result = std::string(buffer) ; - if ( buffer ) delete[] buffer; // free buffer + if ( rc > 0 ) + result = std::string(&buffer[0], need); return result; }