butc: fix int to float conversion warning 77/14277/6
authorCheyenne Wills <cwills@sinenomine.net>
Thu, 16 Jul 2020 21:52:00 +0000 (15:52 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 24 Jul 2020 15:52:32 +0000 (11:52 -0400)
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 <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/butc/tcmain.c

index ed583a7..8402963 100644 (file)
@@ -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);
 }