Address compiler warnings #10
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head There was a failure building this commit

This commit is contained in:
2023-10-30 13:31:52 -05:00
parent e7413fb741
commit 639d14452b
10 changed files with 1129 additions and 631 deletions

View File

@@ -44,7 +44,7 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
allocation_size = file_size;
}
allocation_size =
((allocation_size == 0u) ? WINFSP_ALLOCATION_UNIT : allocation_size);
((allocation_size == 0U) ? WINFSP_ALLOCATION_UNIT : allocation_size);
allocation_size =
utils::divide_with_ceiling(allocation_size, WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
@@ -55,18 +55,18 @@ auto calculate_read_size(const uint64_t &total_size, std::size_t read_size,
const uint64_t &offset) -> std::size_t {
return static_cast<std::size_t>(
((offset + read_size) > total_size)
? ((offset < total_size) ? total_size - offset : 0u)
? ((offset < total_size) ? total_size - offset : 0U)
: read_size);
}
auto compare_version_strings(std::string version1, std::string version2)
-> int {
if (utils::string::contains(version1, "-")) {
version1 = utils::string::split(version1, '-')[0u];
version1 = utils::string::split(version1, '-')[0U];
}
if (utils::string::contains(version2, "-")) {
version2 = utils::string::split(version2, '-')[0u];
version2 = utils::string::split(version2, '-')[0U];
}
auto nums1 = utils::string::split(version1, '.');
@@ -80,11 +80,11 @@ auto compare_version_strings(std::string version1, std::string version2)
nums1.emplace_back("0");
}
for (std::size_t i = 0u; i < nums1.size(); i++) {
for (std::size_t i = 0U; i < nums1.size(); i++) {
const auto int1 = utils::string::to_uint32(nums1[i]);
const auto int2 = utils::string::to_uint32(nums2[i]);
const auto res = std::memcmp(&int1, &int2, sizeof(int1));
if (res) {
if (res != 0) {
return res;
}
}
@@ -105,15 +105,15 @@ auto convert_api_date(const std::string &date) -> std::uint64_t {
#else
strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#endif
return nanos + (mktime(&tm1) * NANOS_PER_SECOND);
return nanos + (static_cast<std::uint64_t>(mktime(&tm1)) * NANOS_PER_SECOND);
}
auto create_curl() -> CURL * {
static std::recursive_mutex mtx;
unique_recur_mutex_lock l(mtx);
unique_recur_mutex_lock lock(mtx);
curl_global_init(CURL_GLOBAL_DEFAULT);
l.unlock();
lock.unlock();
return reset_curl(curl_easy_init());
}
@@ -132,9 +132,9 @@ auto create_uuid_string() -> std::string {
return ret;
#else
#if __linux__
uuid id;
id.make(UUID_MAKE_V4);
return id.string();
uuid guid;
guid.make(UUID_MAKE_V4);
return guid.string();
#else
uuid_t guid;
uuid_generate_random(guid);
@@ -148,8 +148,8 @@ auto create_uuid_string() -> std::string {
#endif
}
auto create_volume_label(const provider_type &pt) -> std::string {
return "repertory_" + app_config::get_provider_name(pt);
auto create_volume_label(const provider_type &prov) -> std::string {
return "repertory_" + app_config::get_provider_name(prov);
}
auto download_type_from_string(std::string type,
@@ -158,9 +158,13 @@ auto download_type_from_string(std::string type,
type = utils::string::to_lower(utils::string::trim(type));
if (type == "direct") {
return download_type::direct;
} else if (type == "fallback") {
}
if (type == "fallback") {
return download_type::fallback;
} else if (type == "ring_buffer") {
}
if (type == "ring_buffer") {
return download_type::ring_buffer;
}
@@ -192,20 +196,18 @@ auto filetime_to_unix_time(const FILETIME &ft) -> remote::file_time {
}
void unix_time_to_filetime(const remote::file_time &ts, FILETIME &ft) {
const auto winTime = (ts / 100ull) + 116444736000000000ull;
ft.dwHighDateTime = winTime >> 32u;
ft.dwLowDateTime = winTime & 0xFFFFFFFF;
const auto win_time = (ts / 100ULl) + 116444736000000000ull;
ft.dwHighDateTime = win_time >> 32u;
ft.dwLowDateTime = win_time & 0xFFFFFFFF;
}
#endif
auto generate_random_string(std::uint16_t length) -> std::string {
srand(static_cast<unsigned int>(get_time_now()));
std::string ret;
ret.resize(length);
for (std::uint16_t i = 0u; i < length; i++) {
for (std::uint16_t i = 0U; i < length; i++) {
do {
ret[i] = static_cast<char>(rand() % 74 + 48);
ret[i] = static_cast<char>(repertory_rand<std::uint8_t>() % 74 + 48);
} while (((ret[i] >= 91) && (ret[i] <= 96)) ||
((ret[i] >= 58) && (ret[i] <= 64)));
}
@@ -219,17 +221,21 @@ auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD {
auto get_environment_variable(const std::string &variable) -> std::string {
#ifdef _WIN32
std::string value;
std::string val;
auto sz = ::GetEnvironmentVariable(&variable[0], nullptr, 0);
if (sz > 0) {
value.resize(sz);
::GetEnvironmentVariable(&variable[0], &value[0], sz);
val.resize(sz);
::GetEnvironmentVariable(&variable[0], &val[0], sz);
}
return value.c_str();
#else
const auto *v = getenv(variable.c_str());
return std::string(v ? v : "");
static std::mutex mtx{};
mutex_lock lock{mtx};
const auto *val = std::getenv(variable.c_str());
auto ret = std::string(val == nullptr ? "" : val);
return ret;
#endif
}
@@ -253,8 +259,11 @@ void get_local_time_now(struct tm &local_time) {
#ifdef _WIN32
localtime_s(&local_time, &now);
#else
static std::mutex mtx{};
mutex_lock lock{mtx};
const auto *tmp = std::localtime(&now);
if (tmp) {
if (tmp != nullptr) {
memcpy(&local_time, tmp, sizeof(local_time));
}
#endif
@@ -264,18 +273,19 @@ auto get_next_available_port(std::uint16_t first_port,
std::uint16_t &available_port) -> bool {
using namespace boost::asio;
using ip::tcp;
boost::system::error_code ec;
boost::system::error_code error_code;
do {
io_service svc;
tcp::acceptor a(svc);
a.open(tcp::v4(), ec) || a.bind({tcp::v4(), first_port}, ec);
} while (ec && (first_port++ < 65535u));
tcp::acceptor acceptor(svc);
acceptor.open(tcp::v4(), error_code) ||
acceptor.bind({tcp::v4(), first_port}, error_code);
} while (error_code && (first_port++ < 65535U));
if (not ec) {
if (not error_code) {
available_port = first_port;
}
return not ec;
return not error_code;
}
auto get_time_now() -> std::uint64_t {
@@ -305,41 +315,44 @@ auto reset_curl(CURL *curl_handle) -> CURL * {
}
auto retryable_action(const std::function<bool()> &action) -> bool {
static constexpr const auto retry_count = 20U;
auto succeeded = false;
for (std::uint8_t i = 0u; not(succeeded = action()) && (i < 20u); i++) {
for (std::uint8_t i = 0U; not(succeeded = action()) && (i < retry_count);
i++) {
std::this_thread::sleep_for(100ms);
}
return succeeded;
}
void spin_wait_for_mutex(std::function<bool()> complete,
std::condition_variable &cv, std::mutex &mtx,
std::condition_variable &cond, std::mutex &mtx,
const std::string &text) {
while (not complete()) {
unique_mutex_lock l(mtx);
unique_mutex_lock lock(mtx);
if (not complete()) {
if (not text.empty()) {
/* event_system::instance().raise<DebugLog>(__FUNCTION__,
* "spin_wait_for_mutex", text); */
}
cv.wait_for(l, 1s);
cond.wait_for(lock, 1s);
}
l.unlock();
lock.unlock();
}
}
void spin_wait_for_mutex(bool &complete, std::condition_variable &cv,
void spin_wait_for_mutex(bool &complete, std::condition_variable &cond,
std::mutex &mtx, const std::string &text) {
while (not complete) {
unique_mutex_lock l(mtx);
unique_mutex_lock lock(mtx);
if (not complete) {
if (not text.empty()) {
/* event_system::instance().raise<DebugLog>(__FUNCTION__,
* "spin_wait_for_mutex", text); */
}
cv.wait_for(l, 1s);
cond.wait_for(lock, 1s);
}
l.unlock();
lock.unlock();
}
}
} // namespace repertory::utils