Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Avoid warning about imprecise int to float conversion



A few months ago, I started getting the following warning:

gcc -c -I. -I../../Src -I../../Src -I../../Src/Zle -I. -I/usr/local/Cellar/pcre2/10.47_1/include -I/usr/local/Cellar/pcre2/10.47_1/include  -DHAVE_CONFIG_H -DMODULE -Wall -Wmissing-prototypes -ggdb -fno-common -o system..o system.c
system.c:642:38: warning: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808
      [-Wimplicit-const-int-float-conversion]
  642 |                     || timeout_param.u.d > 0.999 * LONG_MAX) {
      |                                                  ~ ^~~~~~~~
/Library/Developer/CommandLineTools/usr/lib/clang/21/include/limits.h:51:19: note: expanded from macro 'LONG_MAX'
   51 | #define LONG_MAX  __LONG_MAX__
      |                   ^~~~~~~~~~~~
<built-in>:62:22: note: expanded from macro '__LONG_MAX__'
   62 | #define __LONG_MAX__ 9223372036854775807L
      |                      ^~~~~~~~~~~~~~~~~~~~
1 warning generated.


My gcc version is the following:

% gcc --version          
Apple clang version 21.0.0 (clang-2100.1.1.101)
Target: x86_64-apple-darwin25.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

The following patch computes the same value but without warning.

- Avoid warning about imprecise int to float conversion

Philippe

diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index 57daf0d87..9ff2318c4 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -639,7 +639,7 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 		}
 		timeout_param.u.d = ceil(timeout_param.u.d * 1e6);
 		if (timeout_param.u.d < 1
-		    || timeout_param.u.d > 0.999 * LONG_MAX) {
+		    || timeout_param.u.d > -(0.999 * LONG_MIN)) {
 		    zwarnnam(nam, "flock: invalid interval value: '%s'",
 			     optarg);
 		    return 1;


Messages sorted by: Reverse Date, Date, Thread, Author