From 63a6b3bdba6fe2ce4a125e87ebb2299c903e0e20 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 12 Dec 2023 14:48:52 -0600 Subject: [PATCH] address windows compiler warnings --- src/utils/file_utils.cpp | 17 +++++++++-------- src/utils/native_file.cpp | 8 ++++---- src/utils/utils.cpp | 11 ++++++----- src/utils/windows/windows_utils.cpp | 14 +++++++------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/utils/file_utils.cpp b/src/utils/file_utils.cpp index 3664dd9f..294b860d 100644 --- a/src/utils/file_utils.cpp +++ b/src/utils/file_utils.cpp @@ -30,9 +30,9 @@ namespace repertory::utils::file { auto calculate_used_space(std::string path, bool recursive) -> std::uint64_t { path = utils::path::absolute(path); - std::uint64_t ret = 0u; + std::uint64_t ret{}; #ifdef _WIN32 - WIN32_FIND_DATA fd = {0}; + WIN32_FIND_DATA fd{}; const auto search = utils::path::combine(path, {"*.*"}); auto find = ::FindFirstFile(search.c_str(), &fd); if (find != INVALID_HANDLE_VALUE) { @@ -118,7 +118,7 @@ auto copy_directory_recursively(std::string from_path, std::string to_path) auto ret = create_full_directory_path(to_path); if (ret) { #ifdef _WIN32 - WIN32_FIND_DATA fd = {0}; + WIN32_FIND_DATA fd{}; const auto search = utils::path::combine(from_path, {"*.*"}); auto find = ::FindFirstFile(search.c_str(), &fd); if (find != INVALID_HANDLE_VALUE) { @@ -209,7 +209,7 @@ auto delete_directory_recursively(std::string path) -> bool { path = utils::path::absolute(path); #ifdef _WIN32 - WIN32_FIND_DATA fd = {0}; + WIN32_FIND_DATA fd{}; const auto search = utils::path::combine(path, {"*.*"}); auto find = ::FindFirstFile(search.c_str(), &fd); if (find != INVALID_HANDLE_VALUE) { @@ -361,7 +361,7 @@ auto get_directory_files(std::string path, bool oldest_first, bool recursive) std::deque ret; std::unordered_map lookup; #ifdef _WIN32 - WIN32_FIND_DATA fd = {0}; + WIN32_FIND_DATA fd{}; const auto search = utils::path::combine(path, {"*.*"}); auto find = ::FindFirstFile(search.c_str(), &fd); if (find != INVALID_HANDLE_VALUE) { @@ -531,13 +531,14 @@ auto is_file(const std::string &path) -> bool { auto is_modified_date_older_than(const std::string &path, const std::chrono::hours &hours) -> bool { auto ret = false; - std::uint64_t modified = 0; + std::uint64_t modified{}; if (get_modified_time(path, modified)) { const auto seconds = std::chrono::duration_cast(hours); #ifdef _WIN32 - return (std::chrono::system_clock::from_time_t(modified) + seconds) < - std::chrono::system_clock::now(); + return (std::chrono::system_clock::from_time_t( + static_cast(modified)) + + seconds) < std::chrono::system_clock::now(); #else return (modified + static_cast(seconds.count() * NANOS_PER_SECOND)) < diff --git a/src/utils/native_file.cpp b/src/utils/native_file.cpp index 44596819..79b5665c 100644 --- a/src/utils/native_file.cpp +++ b/src/utils/native_file.cpp @@ -116,7 +116,7 @@ auto native_file::open(const std::string &source_path, auto native_file::allocate(std::uint64_t file_size) -> bool { #ifdef _WIN32 LARGE_INTEGER li{}; - li.QuadPart = file_size; + li.QuadPart = static_cast(file_size); return (::SetFilePointerEx(handle_, li, nullptr, FILE_BEGIN) && ::SetEndOfFile(handle_)); #endif @@ -214,7 +214,7 @@ auto native_file::read_bytes(char *buffer, std::size_t read_size, auto ret = false; bytes_read = 0u; LARGE_INTEGER li{}; - li.QuadPart = read_offset; + li.QuadPart = static_cast(read_offset); if ((ret = !!::SetFilePointerEx(handle_, li, nullptr, FILE_BEGIN))) { DWORD current_read = 0u; do { @@ -253,7 +253,7 @@ auto native_file::truncate(std::uint64_t file_size) -> bool { #ifdef _WIN32 recur_mutex_lock l(read_write_mutex_); LARGE_INTEGER li{}; - li.QuadPart = file_size; + li.QuadPart = static_cast(file_size); return (::SetFilePointerEx(handle_, li, nullptr, FILE_BEGIN) && ::SetEndOfFile(handle_)); #else @@ -271,7 +271,7 @@ auto native_file::write_bytes(const char *buffer, std::size_t write_size, auto ret = true; LARGE_INTEGER li{}; - li.QuadPart = write_offset; + li.QuadPart = static_cast(write_offset); if ((ret = !!::SetFilePointerEx(handle_, li, nullptr, FILE_BEGIN))) { do { DWORD current_write = 0u; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index eca5a764..3b99dd69 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -170,16 +170,16 @@ auto download_type_to_string(const download_type &type) -> std::string { // https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ auto filetime_to_unix_time(const FILETIME &ft) -> remote::file_time { LARGE_INTEGER date{}; - date.HighPart = ft.dwHighDateTime; + date.HighPart = static_cast(ft.dwHighDateTime); date.LowPart = ft.dwLowDateTime; - date.QuadPart -= 116444736000000000ULL; + date.QuadPart -= 116444736000000000LL; - return date.QuadPart * 100ULL; + return static_cast(date.QuadPart) * 100ULL; } void unix_time_to_filetime(const remote::file_time &ts, FILETIME &ft) { const auto win_time = (ts / 100ULL) + 116444736000000000ULL; - ft.dwHighDateTime = win_time >> 32U; + ft.dwHighDateTime = static_cast(win_time >> 32U); ft.dwLowDateTime = win_time & 0xFFFFFFFF; } #endif @@ -216,7 +216,8 @@ auto get_file_time_now() -> std::uint64_t { ::GetSystemTime(&st); FILETIME ft{}; ::SystemTimeToFileTime(&st, &ft); - return static_cast(((LARGE_INTEGER *)&ft)->QuadPart); + return static_cast( + (reinterpret_cast(&ft))->QuadPart); #else return get_time_now(); #endif diff --git a/src/utils/windows/windows_utils.cpp b/src/utils/windows/windows_utils.cpp index 8085286c..10626e8e 100644 --- a/src/utils/windows/windows_utils.cpp +++ b/src/utils/windows/windows_utils.cpp @@ -28,7 +28,7 @@ #include "utils/string_utils.hpp" #ifndef STATUS_DEVICE_INSUFFICIENT_RESOURCES -#define STATUS_DEVICE_INSUFFICIENT_RESOURCES ((NTSTATUS)0xC0000468L) +#define STATUS_DEVICE_INSUFFICIENT_RESOURCES static_cast(0xC0000468L) #endif namespace repertory::utils { @@ -95,9 +95,9 @@ auto get_local_app_data_directory() -> const std::string & { PWSTR local_app_data{}; if (SUCCEEDED(::SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &local_app_data))) { - auto app_data = utils::string::to_utf8(local_app_data); + auto ret = utils::string::to_utf8(local_app_data); ::CoTaskMemFree(local_app_data); - return app_data; + return ret; } throw startup_exception("unable to detect local application data folder"); @@ -164,14 +164,14 @@ auto run_process_elevated(std::vector args) -> int { sei.nShow = SW_NORMAL; if (::ShellExecuteEx(&sei)) { ::WaitForSingleObject(sei.hProcess, INFINITE); - DWORD exit_code = 0u; + DWORD exit_code{}; ::GetExitCodeProcess(sei.hProcess, &exit_code); ::CloseHandle(sei.hProcess); - return exit_code; + return static_cast(exit_code); } } - return ::GetLastError(); + return static_cast(::GetLastError()); } void set_last_error_code(DWORD error_code) { ::SetLastError(error_code); } @@ -234,7 +234,7 @@ auto unix_open_flags_to_flags_and_perms(const remote::file_mode & /*mode*/, } auto time64_to_unix_time(const __time64_t &t) -> remote::file_time { - return t * NANOS_PER_SECOND; + return static_cast(t * NANOS_PER_SECOND); } } // namespace repertory::utils