Part of adventure's interesting internal obfuscation scheme makes clang
very unhappy. It spews 240+ warnings of this kind:

/usr/src/games/adventure/wizard.c:71:17: warning: implicit conversion from 
'int' to 'char' changes value from 143 to -113
      [-Wconstant-conversion]
        strlcpy(magic, DECR(d,w,a,r,f), sizeof magic);
                       ^~~~~~~~~~~~~~~
/usr/src/games/adventure/hdr.h:159:33: note: expanded from macro 'DECR'
#define DECR(a,b,c,d,e) decr(*#a+'+',*#b+'-',*#c+'#',*#d+'&',*#e+'%')

To avoid both, the warning and the signed underflow in decr(), let's do
this no-op the other way around: subtract in the DECR macro and add back
in decr().

Note that decr() is never called directly, it's only used via the
DECR macro.

Index: hdr.h
===================================================================
RCS file: /var/cvs/src/games/adventure/hdr.h,v
retrieving revision 1.16
diff -u -p -r1.16 hdr.h
--- hdr.h       10 Apr 2017 13:56:16 -0000      1.16
+++ hdr.h       14 May 2017 16:36:49 -0000
@@ -156,4 +156,4 @@ int turns, lmwarn, iwest, knfloc, detail
 int    demo, limit;
 
 /* We need to get a little tricky to avoid strings */
-#define DECR(a,b,c,d,e) decr(*#a+'+',*#b+'-',*#c+'#',*#d+'&',*#e+'%')
+#define DECR(a,b,c,d,e) decr(*#a-'+',*#b-'-',*#c-'#',*#d-'&',*#e-'%')
Index: init.c
===================================================================
RCS file: /var/cvs/src/games/adventure/init.c,v
retrieving revision 1.15
diff -u -p -r1.15 init.c
--- init.c      8 Mar 2016 10:48:39 -0000       1.15
+++ init.c      14 May 2017 16:36:59 -0000
@@ -66,11 +66,11 @@ decr(char a, char b, char c, char d, cha
 {
        static char buf[6];
 
-       buf[0] = a - '+';
-       buf[1] = b - '-';
-       buf[2] = c - '#';
-       buf[3] = d - '&';
-       buf[4] = e - '%';
+       buf[0] = a + '+';
+       buf[1] = b + '-';
+       buf[2] = c + '#';
+       buf[3] = d + '&';
+       buf[4] = e + '%';
        buf[5] = 0;
        return buf;
 }

Reply via email to