hoytech / vmtouch

Portable file system cache diagnostics and control
https://hoytech.com/vmtouch/
BSD 3-Clause "New" or "Revised" License
1.79k stars 210 forks source link

implicit conversion from 'long long' to 'double' changes value #105

Open ryandesign opened 11 months ago

ryandesign commented 11 months ago

I noticed that this warning occurs when building vmtouch 1.3.1 with llvm.org clang 12, 13, 14, 15, 16, 17:

vmtouch.c:318:13: warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-int-float-conversion]
  if (val > INT64_MAX) fatal(errstr);
          ~ ^~~~~~~~~
/usr/include/stdint.h:122:26: note: expanded from macro 'INT64_MAX'
#define INT64_MAX        9223372036854775807LL
                         ^~~~~~~~~~~~~~~~~~~~~

On the next line you return (int64_t) val so maybe you want to cast val to int64_t for the INT64_MAX comparison too; that eliminates the warning:

--- vmtouch.c.orig  2018-11-16 08:40:02.000000000 -0600
+++ vmtouch.c   2023-10-01 17:34:40.000000000 -0500
@@ -315,7 +315,7 @@

   val *= mult;

-  if (val > INT64_MAX) fatal(errstr);
+  if ((int64_t) val > INT64_MAX) fatal(errstr);

   return (int64_t) val;
 }