diff --git a/app/actions.cpp b/app/actions.cpp index 5e933af780..d7343f9866 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -1669,7 +1669,7 @@ std::string temporaryPath() { auto guard = std::scoped_lock(cs); #if defined(_WIN32) - HANDLE process = 0; + HANDLE process = nullptr; DWORD pid = ::GetProcessId(process); #else pid_t pid = ::getpid(); diff --git a/app/exiv2.cpp b/app/exiv2.cpp index 8dd4d9a001..106ca1dca4 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -1280,15 +1280,15 @@ bool parseCmdLines(ModifyCmds& modifyCmds, const Params::CmdLines& cmdLines) { } // parseCmdLines #ifdef _WIN32 -static std::string formatArg(const char* arg) { - std::string result = ""; +std::string formatArg(const char* arg) { + std::string result; char b = ' '; char e = '\\'; std::string E = std::string("\\"); char q = '\''; std::string Q = std::string("'"); bool qt = false; - char* a = (char*)arg; + char* a = const_cast(arg); while (*a) { if (*a == b || *a == e || *a == q) qt = true; diff --git a/include/exiv2/quicktimevideo.hpp b/include/exiv2/quicktimevideo.hpp index 25923fd5e4..840e99c608 100644 --- a/include/exiv2/quicktimevideo.hpp +++ b/include/exiv2/quicktimevideo.hpp @@ -206,7 +206,6 @@ class QuickTimeVideo : public Image { */ void aspectRatio(); - private: //! Variable which stores Time Scale unit, used to calculate time. uint64_t timeScale_ = 0; //! Variable which stores current stream being processsed. diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index f681cd825f..dd82be4f09 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -1270,8 +1270,8 @@ class ValueType : public Value { } // Check for integer overflow. -#if __cplusplus >= 201703L - if (std::is_signed_v == std::is_signed_v) { +#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L + if constexpr (std::is_signed_v == std::is_signed_v) { #else if (std::is_signed::value == std::is_signed::value) { #endif @@ -1281,13 +1281,13 @@ class ValueType : public Value { if (imax < b || a < imin || imax < a) { return 0; } -#if __cplusplus >= 201703L - } else if (std::is_signed_v) { +#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L + } else if constexpr (std::is_signed_v) { #else } else if (std::is_signed::value) { #endif // conversion is from unsigned to signed -#if __cplusplus >= 201402L +#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L const auto imax = static_cast>(std::numeric_limits::max()); #else const auto imax = static_cast::type>(std::numeric_limits::max()); @@ -1302,7 +1302,7 @@ class ValueType : public Value { return 0; } // Inputs are not negative so convert them to unsigned. -#if __cplusplus >= 201402L +#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L const auto a_u = static_cast>(a); const auto b_u = static_cast>(b); #else diff --git a/src/basicio.cpp b/src/basicio.cpp index 5d1c342bf4..5192f9a4d9 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -199,9 +199,9 @@ int FileIo::munmap() { #elif defined _WIN32 UnmapViewOfFile(p_->pMappedArea_); CloseHandle(p_->hMap_); - p_->hMap_ = 0; + p_->hMap_ = nullptr; CloseHandle(p_->hFile_); - p_->hFile_ = 0; + p_->hFile_ = nullptr; #else #error Platforms without mmap are not supported. See https://github.com/Exiv2/exiv2/issues/2380 if (p_->isWriteable_) { @@ -259,19 +259,19 @@ byte* FileIo::mmap(bool isWriteable) { flProtect = PAGE_READWRITE; } HANDLE hPh = GetCurrentProcess(); - HANDLE hFd = (HANDLE)_get_osfhandle(fileno(p_->fp_)); + auto hFd = reinterpret_cast(_get_osfhandle(fileno(p_->fp_))); if (hFd == INVALID_HANDLE_VALUE) { throw Error(ErrorCode::kerCallFailed, path(), "MSG1", "_get_osfhandle"); } if (!DuplicateHandle(hPh, hFd, hPh, &p_->hFile_, 0, false, DUPLICATE_SAME_ACCESS)) { throw Error(ErrorCode::kerCallFailed, path(), "MSG2", "DuplicateHandle"); } - p_->hMap_ = CreateFileMapping(p_->hFile_, 0, flProtect, 0, (DWORD)p_->mappedLength_, 0); - if (p_->hMap_ == 0) { + p_->hMap_ = CreateFileMapping(p_->hFile_, nullptr, flProtect, 0, static_cast(p_->mappedLength_), nullptr); + if (p_->hMap_ == nullptr) { throw Error(ErrorCode::kerCallFailed, path(), "MSG3", "CreateFileMapping"); } void* rc = MapViewOfFile(p_->hMap_, dwAccess, 0, 0, 0); - if (rc == 0) { + if (rc == nullptr) { throw Error(ErrorCode::kerCallFailed, path(), "MSG4", "CreateFileMapping"); } p_->pMappedArea_ = static_cast(rc); @@ -367,7 +367,7 @@ void FileIo::transfer(BasicIo& src) { using ReplaceFileA_t = BOOL(WINAPI*)(LPCSTR, LPCSTR, LPCSTR, DWORD, LPVOID, LPVOID); HMODULE hKernel = ::GetModuleHandleA("kernel32.dll"); if (hKernel) { - ReplaceFileA_t pfcn_ReplaceFileA = (ReplaceFileA_t)GetProcAddress(hKernel, "ReplaceFileA"); + auto pfcn_ReplaceFileA = reinterpret_cast(GetProcAddress(hKernel, "ReplaceFileA")); if (pfcn_ReplaceFileA) { BOOL ret = pfcn_ReplaceFileA(pf, fileIo->path().c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr); diff --git a/src/convert.cpp b/src/convert.cpp index a7313471ed..577fd08000 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -1439,7 +1439,7 @@ bool swapBytes(std::string& str) { bool mb2wc(UINT cp, std::string& str) { if (str.empty()) return true; - int len = MultiByteToWideChar(cp, 0, str.c_str(), (int)str.size(), 0, 0); + int len = MultiByteToWideChar(cp, 0, str.c_str(), static_cast(str.size()), nullptr, 0); if (len == 0) { #ifdef EXIV2_DEBUG_MESSAGES EXV_DEBUG << "mb2wc: Failed to determine required size of output buffer.\n"; @@ -1448,7 +1448,8 @@ bool mb2wc(UINT cp, std::string& str) { } std::vector out; out.resize(len * 2); - int ret = MultiByteToWideChar(cp, 0, str.c_str(), (int)str.size(), (LPWSTR)&out[0], len * 2); + int ret = MultiByteToWideChar(cp, 0, str.c_str(), static_cast(str.size()), reinterpret_cast(out.data()), + len * 2); if (ret == 0) { #ifdef EXIV2_DEBUG_MESSAGES EXV_DEBUG << "mb2wc: Failed to convert the input string to a wide character string.\n"; @@ -1468,7 +1469,8 @@ bool wc2mb(UINT cp, std::string& str) { #endif return false; } - int len = WideCharToMultiByte(cp, 0, (LPCWSTR)str.data(), (int)str.size() / 2, 0, 0, 0, 0); + int len = WideCharToMultiByte(cp, 0, reinterpret_cast(str.data()), static_cast(str.size()) / 2, nullptr, + 0, nullptr, nullptr); if (len == 0) { #ifdef EXIV2_DEBUG_MESSAGES EXV_DEBUG << "wc2mb: Failed to determine required size of output buffer.\n"; @@ -1477,7 +1479,8 @@ bool wc2mb(UINT cp, std::string& str) { } std::vector out; out.resize(len); - int ret = WideCharToMultiByte(cp, 0, (LPCWSTR)str.data(), (int)str.size() / 2, (LPSTR)&out[0], len, 0, 0); + int ret = WideCharToMultiByte(cp, 0, reinterpret_cast(str.data()), static_cast(str.size()) / 2, + static_cast(out.data()), len, nullptr, nullptr); if (ret == 0) { #ifdef EXIV2_DEBUG_MESSAGES EXV_DEBUG << "wc2mb: Failed to convert the input string to a multi byte string.\n"; diff --git a/src/version.cpp b/src/version.cpp index 3ae9cc8062..ab063b87ed 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -123,10 +123,10 @@ static std::vector getLoadedLibraries() { // enumerate loaded libraries and determine path to executable HMODULE handles[200]; DWORD cbNeeded; - if (EnumProcessModules(GetCurrentProcess(), handles, DWORD(std::size(handles)), &cbNeeded)) { + if (EnumProcessModules(GetCurrentProcess(), handles, static_cast(std::size(handles)), &cbNeeded)) { char szFilename[_MAX_PATH]; for (DWORD h = 0; h < cbNeeded / sizeof(handles[0]); h++) { - GetModuleFileNameA(handles[h], szFilename, DWORD(std::size(szFilename))); + GetModuleFileNameA(handles[h], szFilename, static_cast(std::size(szFilename))); std::string path(szFilename); pushPath(path, libs, paths); }