]> granicus.if.org Git - nethack/commitdiff
Fix sign/unsigned comparison bug.
authorBart House <bart@barthouse.com>
Mon, 19 Oct 2020 23:19:01 +0000 (16:19 -0700)
committerBart House <bart@barthouse.com>
Mon, 19 Oct 2020 23:19:01 +0000 (16:19 -0700)
We are comparing a signed char with unsigned int.  The signed char will be
sign exetended when converted to unsigned int causing an unexpected
result.

src/teleport.c

index 0e47f97358a1e9c4e946413fed7b35e3c4b0be90..cb8bb4f40e5c665dc27124c1f00c73f6ff3274cc 100644 (file)
@@ -1191,10 +1191,10 @@ struct monst *mtmp;
            sent out of his room (caller might resort to goodpos() if
            we report failure here, so this isn't full prevention) */
         if (mtmp->isshk && inhishop(mtmp)) {
-            if (levl[x][y].roomno != ESHK(mtmp)->shoproom)
+            if (levl[x][y].roomno != (unsigned char) ESHK(mtmp)->shoproom)
                 return FALSE;
         } else if (mtmp->ispriest && inhistemple(mtmp)) {
-            if (levl[x][y].roomno != EPRI(mtmp)->shroom)
+            if (levl[x][y].roomno !=  (unsigned char) EPRI(mtmp)->shroom)
                 return FALSE;
         }
         /* current location is <xx,yy> */