From ffaaaa0a343b8db78a5983cbffc3684cc4c15b0a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 29 Jan 2021 09:25:16 -0500 Subject: [PATCH] casadm: don't cast a float to an int explicitly If an underflowed float number was casted to an int explicitly, it's value was rounded to a lower value. Using `round()` function ensures that the number will be always rounded to a nearest integer. Signed-off-by: Michal Mielewczyk --- casadm/Makefile | 2 +- casadm/cas_lib.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/casadm/Makefile b/casadm/Makefile index 40ee94a..022941a 100644 --- a/casadm/Makefile +++ b/casadm/Makefile @@ -83,7 +83,7 @@ CFLAGS += -Wall -Werror -z relro -z now -fstack-protector -fPIC -Wformat -Wfo # # Flags for linking # -LDFLAGS = -z noexecstack -z relro -z now -pie -pthread +LDFLAGS = -z noexecstack -z relro -z now -pie -pthread -lm # # Targets # diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index b2119a7..6d8d397 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -38,6 +38,7 @@ #include "psort.h" #include #include +#include #define PRINT_STAT(x) header->cmd_input.cache_stats.x @@ -2212,7 +2213,7 @@ static int calculate_max_allocation(uint16_t cache_id, const char *allocation, if (allocation + strnlen(allocation, MAX_STR_LEN) != end) return FAILURE; - *part_size = (uint32_t)(alloc * 100); + *part_size = (uint32_t)round(alloc * 100); return SUCCESS; }