Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy on Windows #2452

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions app/exiv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(arg);
while (*a) {
if (*a == b || *a == e || *a == q)
qt = true;
Expand Down
1 change: 0 additions & 1 deletion include/exiv2/quicktimevideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,8 @@ class ValueType : public Value {
}

// Check for integer overflow.
#if __cplusplus >= 201703L
if (std::is_signed_v<I> == std::is_signed_v<decltype(a)>) {
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
if constexpr (std::is_signed_v<I> == std::is_signed_v<decltype(a)>) {
#else
if (std::is_signed<I>::value == std::is_signed<decltype(a)>::value) {
#endif
Expand All @@ -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<I>) {
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
} else if constexpr (std::is_signed_v<I>) {
#else
} else if (std::is_signed<I>::value) {
#endif
// conversion is from unsigned to signed
#if __cplusplus >= 201402L
#if __cplusplus >= 201402L || _MSVC_LANG >= 201402L
const auto imax = static_cast<std::make_unsigned_t<I>>(std::numeric_limits<I>::max());
#else
const auto imax = static_cast<typename std::make_unsigned<I>::type>(std::numeric_limits<I>::max());
Expand All @@ -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<std::make_unsigned_t<decltype(a)>>(a);
const auto b_u = static_cast<std::make_unsigned_t<decltype(b)>>(b);
#else
Expand Down
14 changes: 7 additions & 7 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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<HANDLE>(_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<DWORD>(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<byte*>(rc);
Expand Down Expand Up @@ -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<ReplaceFileA_t>(GetProcAddress(hKernel, "ReplaceFileA"));
if (pfcn_ReplaceFileA) {
BOOL ret =
pfcn_ReplaceFileA(pf, fileIo->path().c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr);
Expand Down
11 changes: 7 additions & 4 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(str.size()), nullptr, 0);
if (len == 0) {
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "mb2wc: Failed to determine required size of output buffer.\n";
Expand All @@ -1448,7 +1448,8 @@ bool mb2wc(UINT cp, std::string& str) {
}
std::vector<std::string::value_type> 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<int>(str.size()), reinterpret_cast<LPWSTR>(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";
Expand All @@ -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<LPCWSTR>(str.data()), static_cast<int>(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";
Expand All @@ -1477,7 +1479,8 @@ bool wc2mb(UINT cp, std::string& str) {
}
std::vector<std::string::value_type> 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<LPCWSTR>(str.data()), static_cast<int>(str.size()) / 2,
static_cast<LPSTR>(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";
Expand Down
4 changes: 2 additions & 2 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ static std::vector<std::string> 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<DWORD>(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<DWORD>(std::size(szFilename)));
std::string path(szFilename);
pushPath(path, libs, paths);
}
Expand Down