From 5eebbbcbfb2a809eae63ee730db2bf614d2a8053 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 11 Feb 2023 14:40:19 -0800 Subject: [PATCH] make conversions explicit Found with MSVC's C4244 Signed-off-by: Rosen Penev --- app/exiv2.cpp | 2 +- src/futils.cpp | 2 +- src/image.cpp | 6 +++--- src/sonymn_int.cpp | 2 +- src/version.cpp | 3 +-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/exiv2.cpp b/app/exiv2.cpp index e0838b93..874f11cb 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -469,7 +469,7 @@ int Params::option(int opt, const std::string& optArg, int optOpt) { int Params::setLogLevel(const std::string& optArg) { int rc = 0; - const char logLevel = tolower(optArg[0]); + const auto logLevel = static_cast(tolower(optArg[0])); switch (logLevel) { case 'd': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::debug); diff --git a/src/futils.cpp b/src/futils.cpp index 38896ced..02764115 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -81,7 +81,7 @@ char to_hex(char code) { /// @brief Convert a hex character to its integer value. char from_hex(char ch) { - return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; + return isdigit(ch) ? ch - '0' : static_cast(tolower(ch)) - 'a' + 10; } std::string urlencode(const std::string& str) { diff --git a/src/image.cpp b/src/image.cpp index 9a235158..7857896f 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -469,9 +469,9 @@ void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStruct if (bNikon) { // tag is an embedded tiff const long byteslen = count - jump; - DataBuf bytes(byteslen); // allocate a buffer - io.readOrThrow(bytes.data(), byteslen, ErrorCode::kerCorruptedMetadata); // read - MemIo memIo(bytes.c_data(), byteslen); // create a file + auto b = DataBuf(byteslen); // allocate a buffer + io.readOrThrow(b.data(), byteslen, ErrorCode::kerCorruptedMetadata); // read + MemIo memIo(b.c_data(), byteslen); // create a file printTiffStructure(memIo, out, option, depth + 1); } else { // tag is an IFD diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index cd309954..751f8aff 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -2289,7 +2289,7 @@ static DataBuf sonyTagCipher(uint16_t /* tag */, const byte* bytes, size_t size, byte code[256]; for (uint32_t i = 0; i < 249; i++) { if (bDecipher) { - code[(i * i * i) % 249] = i; + code[(i * i * i) % 249] = static_cast(i); } else { code[i] = (i * i * i) % 249; } diff --git a/src/version.cpp b/src/version.cpp index 919f7101..afe94fb4 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -127,8 +127,7 @@ static std::vector getLoadedLibraries() { char szFilename[_MAX_PATH]; for (DWORD h = 0; h < cbNeeded / sizeof(handles[0]); h++) { GetModuleFileNameA(handles[h], szFilename, static_cast(std::size(szFilename))); - std::string path(szFilename); - pushPath(path, libs, paths); + pushPath(szFilename, libs, paths); } } #elif defined(__APPLE__)