]> granicus.if.org Git - nethack/commitdiff
fix issue #689 - ?: warning
authorPatR <rankin@nethack.org>
Thu, 3 Mar 2022 13:27:05 +0000 (05:27 -0800)
committerPatR <rankin@nethack.org>
Thu, 3 Mar 2022 13:27:05 +0000 (05:27 -0800)
From copperwater:  a recently added use of <test> ? <if> : <else>
had a ptrdiff_t (signed) expression for <if> and a size_t (unsigned)
expression for <else> which triggered a sign-compare warning when
the two expressions are implicitly converted into the same type.

Use casts to convert both expressions to long rather that convert
the size_t half to ptrdiff_t or vice versa.  The final result gets
cast to int already.

Fixes #689

sys/unix/unixmain.c

index 23ac06f8f3ae19d8ee57c1b8d06e5428695793c5..9cd7dfedebc1e641885ba0a59f34cecf027bb8d4 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 unixmain.c      $NHDT-Date: 1645223897 2022/02/18 22:38:17 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.97 $ */
+/* NetHack 3.7 unixmain.c      $NHDT-Date: 1646313937 2022/03/03 13:25:37 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.99 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2011. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -333,7 +333,7 @@ lopt(
     if (p && opttype == ArgValDisallowed)
         goto loptnotallowed;
 
-    l = (int) (p ? (p - arg) : strlen(arg));
+    l = (int) (p ? (long) (p - arg) : (long) strlen(arg));
     if (!strncmp(arg, optname, l)) {
         /* "-windowtype[=foo]" */
         if (p)