From 360f38f81bf99be82b6d08a648be51506f5ddcdd Mon Sep 17 00:00:00 2001 From: Benjamin Summerton Date: Sun, 9 Aug 2020 15:22:59 -0400 Subject: [PATCH] Fix sign conversion issues I was including this on a project of mine where I had `-Wall -Wextra -pedantic` turned on to clean up any extra warnings. I caught about 4 of them in relation to implicit sign and type conversions. Adding some `static_cast<>` calls and changing a data type resolved all of the warnings. --- include/progresscpp/ProgressBar.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/progresscpp/ProgressBar.hpp b/include/progresscpp/ProgressBar.hpp index e4c4cf3..0f0b12e 100644 --- a/include/progresscpp/ProgressBar.hpp +++ b/include/progresscpp/ProgressBar.hpp @@ -23,15 +23,15 @@ class ProgressBar { unsigned int operator++() { return ++ticks; } void display() const { - float progress = (float) ticks / total_ticks; - int pos = (int) (bar_width * progress); + float progress = static_cast(ticks) / static_cast(total_ticks); + unsigned int pos = static_cast(static_cast(bar_width) * progress); std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); auto time_elapsed = std::chrono::duration_cast(now - start_time).count(); std::cout << "["; - for (int i = 0; i < bar_width; ++i) { + for (unsigned int i = 0; i < bar_width; ++i) { if (i < pos) std::cout << complete_char; else if (i == pos) std::cout << ">"; else std::cout << incomplete_char;