From 37b55b30c65d0ab8c8eaabfda0dbd90829e2c46a Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Thu, 16 Jul 2020 15:52:00 -0600 Subject: [PATCH] butc: fix int to float conversion warning Building with clang-10 results in 2 warnings/errors associated with with trying to convert 0x7fffffff to a floating point value. tcmain.c:240:18: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror, -Wimplicit-int-float-conversion] if ((total > 0x7fffffff) || (total < 0)) /* Don't go over 2G */ and the same conversion warning on the statement on the following line: total = 0x7fffffff; Use floating point and decimal constants instead of the hex constants. For the test, use 2147483648.0 which is cleanly represented by a float. Change the comparison in the test from '>' to '>='. If the total value exceeds 2G, just assign the max value directly to the return variable. Change-Id: I79b2afa006496a756bd7b50976050c24827aa027 Reviewed-on: https://gerrit.openafs.org/14277 Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- src/butc/tcmain.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/butc/tcmain.c b/src/butc/tcmain.c index ed583a7..8402963 100644 --- a/src/butc/tcmain.c +++ b/src/butc/tcmain.c @@ -237,10 +237,11 @@ atocl(char *numstring, char crunit, afs_int32 *number) total *= 1024.0; total += 0.5; /* Round up */ - if ((total > 0x7fffffff) || (total < 0)) /* Don't go over 2G */ - total = 0x7fffffff; + if ((total >= 2147483648.0) || (total < 0)) /* Don't go over 2G */ + *number = 2147483647; + else + *number = total; - *number = total; return (0); } -- 1.9.4