]> granicus.if.org Git - nethack/commitdiff
add '(uchar)' casts to ctype calls
authorPatR <rankin@nethack.org>
Tue, 19 Jul 2016 12:40:09 +0000 (05:40 -0700)
committerPatR <rankin@nethack.org>
Tue, 19 Jul 2016 12:40:09 +0000 (05:40 -0700)
This is from the pull request for the assertion failure fix.  It
did not mention how to reproduce the assertion failure, just added
casts to a bunch of isspace/isprint/tolower calls that didn't already
have such.

I removed an obsolete change for win/tty/topl.c and changed the
win/win32/mswproc.c code to avoid using an expression with side-effects
(*colorstring++) in calls to tolower() in case someone overrides that
with a macro which evaluates its argument more than once as some pre-
ANSI ones used to do.  Not tested, might have typos....

sys/wince/*.c still needs similar casts.

src/attrib.c
sys/share/pcsys.c
sys/winnt/nh340key.c
sys/winnt/nhdefkey.c
sys/winnt/nhraykey.c
sys/winnt/winnt.c
util/makedefs.c
win/share/tiletext.c
win/win32/mhmenu.c
win/win32/mhmsgwnd.c
win/win32/mswproc.c

index 1eb709d22fd58db9ad8aa678e3f2533d1b055e5d..5c80c5ed23f3efdbd0bf8c14ac3db0f2df92d5cd 100644 (file)
@@ -245,7 +245,8 @@ boolean thrown_weapon; /* thrown weapons are less deadly */
         boolean plural = (reason[strlen(reason) - 1] == 's') ? 1 : 0;
 
         /* avoid "The" Orcus's sting was poisoned... */
-        pline("%s%s %s poisoned!", isupper(*reason) ? "" : "The ", reason,
+        pline("%s%s %s poisoned!",
+              isupper((uchar) *reason) ? "" : "The ", reason,
               plural ? "were" : "was");
     }
     if (Poison_resistance) {
index 47f74a717b148ebfe6873cd55147d92cbf92d4f3..085956c7633316631cacb0435c6244dcd14ab8aa 100644 (file)
@@ -299,7 +299,7 @@ int start;
          * whitespace, do not change the value of SAVEF.
          */
         for (bp = buf; *bp; bp++)
-            if (!isspace(*bp)) {
+            if (!isspace((uchar) *bp)) {
                 strncpy(SAVEF, bp, PATHLEN);
                 break;
             }
index 7d64b3843a53a4c60634122f284ce63bf0b9e597..8d512142ea7eb9b282c665b5a74be59c9a0332de 100644 (file)
@@ -153,7 +153,7 @@ int portdebug;
         if (vk == 0xBF)
             ch = M('?');
         else
-            ch = M(tolower(keycode));
+            ch = M(tolower((uchar) keycode));
     }
     if (ch == '\r')
         ch = '\n';
index 258874e5407304897c7805ba01709da686b0a29d..5f7390955308b5a09356a9465c8692c6228ac0d4 100644 (file)
@@ -167,7 +167,7 @@ int portdebug;
         if (vk == 0xBF)
             ch = M('?');
         else
-            ch = M(tolower(keycode));
+            ch = M(tolower((uchar) keycode));
     }
     /* Attempt to work better with international keyboards. */
     else {
index cae80ccd8d671163c87c3fa7610d85920df31eed..3b0a6ef044a08e54a6d0ad01a5d1eb0fc874fe9e 100644 (file)
@@ -352,7 +352,7 @@ int portdebug;
         if (vk == 0xBF)
             ch = M('?');
         else
-            ch = M(tolower(keycode));
+            ch = M(tolower((uchar) keycode));
     } else if (ch < 32 && !isnumkeypad(scan)) {
         /* Control code; ReadConsole seems to filter some of these,
          * including ESC */
index e95fe4f1d09f206cc68528fa1c1586dcb50bf38c..892744432bc9431b08571a4b8c9042f2ce8b34d7 100644 (file)
@@ -119,7 +119,7 @@ char *str;
     char *ptr;
     char drive;
     if ((ptr = index(str, ':')) != (char *) 0) {
-        drive = toupper(*(ptr - 1));
+        drive = toupper((uchar) *(ptr - 1));
         _chdrive((drive - 'A') + 1);
     }
 }
index 6ae0cefc95d696ab64265ba6c8844e2a9d8a55f7..25614d8b28bc778945835e7086cb643ae9751acd 100644 (file)
@@ -653,7 +653,7 @@ const char *id;
 {
     struct grep_var *rv;
 
-    while (*id && isspace(*id))
+    while (*id && isspace((uchar) *id))
         id++;
     if (!*id) {
         Fprintf(stderr, "missing identifier in line %d", grep_lineno);
@@ -700,10 +700,10 @@ char *buf;
     int isif = 1;
     char *buf0 = buf;
 #if 1
-    if (isspace(buf[0]))
+    if (isspace((uchar) buf[0]))
         return &buf[-1]; /* XXX see docs above */
 #else
-    while (buf[0] && isspace(buf[0]))
+    while (buf[0] && isspace((uchar) buf[0]))
         buf++;
 #endif
     switch (buf[0]) {
@@ -754,7 +754,7 @@ char *buf;
     default: {
         char str[10];
 
-        if (isprint(buf[0])) {
+        if (isprint((uchar) buf[0])) {
             str[0] = buf[0];
             str[1] = '\0';
         } else {
index 8d913f8970420be73e6f253be5946e0da245c393..f2ee7bf0344b2ef14d0faadef29d11a3d0fd86aa 100644 (file)
@@ -181,7 +181,7 @@ pixel (*pixels)[TILE_X];
     /* DICE again... it doesn't seem to eat whitespace after the } like
      * it should, so we have to do so manually.
      */
-    while ((*c = fgetc(txtfile)) != EOF && isspace(*c))
+    while ((*c = fgetc(txtfile)) != EOF && isspace((uchar) *c))
         ;
     ungetc(*c, txtfile);
 #endif
index 74cee9880d37801a6d8a773d59bc994a275b2597..6c07b5081336e333964b7f6390e9577cc6dbc681 100644 (file)
@@ -1412,7 +1412,7 @@ onListChar(HWND hWnd, HWND hwndList, WORD ch)
             }
         }
 
-        if (isdigit(ch)) {
+        if (isdigit((uchar) ch)) {
             int count;
             i = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED);
             if (i >= 0) {
index e30a099b31e71756e607103581ac0cd51de945cd..40b4791ef24d1e3a13755646f4b92480b11ac7c8 100644 (file)
@@ -310,7 +310,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
 
                 /* check if the string is empty */
                 for (p = data->window_text[MSG_LINES - 1].text;
-                     *p && isspace(*p); p++)
+                     *p && isspace((uchar) *p); p++)
                     ;
 
                 if (*p) {
index b514883320aa6d28d6cf1390877ca8d1fe2621e1..7247dbbb313cbe7a1d38cea541df64c62dda4783 100644 (file)
@@ -1583,7 +1583,7 @@ mswin_yn_function(const char *question, const char *choices, CHAR_P def)
                 (WPARAM) MSNH_MSG_CARET, (LPARAM) &createcaret);
 
     /* display selection in the message window */
-    if (isprint(ch) && ch != '#') {
+    if (isprint((uchar) ch) && ch != '#') {
         res_ch[0] = ch;
         res_ch[1] = '\x0';
         mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, res_ch, 1);
@@ -2019,7 +2019,7 @@ mswin_getmsghistory(BOOLEAN_P init)
         if (next_message)
             next_message++;
         if (p)
-            while (p >= retval && isspace(*p))
+            while (p >= retval && isspace((uchar) *p))
                 *p-- = (char) 0; /* delete trailing whitespace */
         return retval;
     }
@@ -2539,23 +2539,32 @@ mswin_color_from_string(char *colorstring, HBRUSH *brushptr,
         if (strlen(++colorstring) != 6)
             return;
 
-        red_value = (int) (index(hexadecimals, tolower(*colorstring++))
+        red_value = (int) (index(hexadecimals, tolower((uchar) *colorstring))
                            - hexadecimals);
+        ++colorstring;
         red_value *= 16;
-        red_value += (int) (index(hexadecimals, tolower(*colorstring++))
+        red_value += (int) (index(hexadecimals, tolower((uchar) *colorstring))
                             - hexadecimals);
+        ++colorstring;
 
-        green_value = (int) (index(hexadecimals, tolower(*colorstring++))
+        green_value = (int) (index(hexadecimals,
+                                   tolower((uchar) *colorstring))
                              - hexadecimals);
+        ++colorstring;
         green_value *= 16;
-        green_value += (int) (index(hexadecimals, tolower(*colorstring++))
+        green_value += (int) (index(hexadecimals,
+                                    tolower((uchar) *colorstring))
                               - hexadecimals);
+        ++colorstring;
 
-        blue_value = (int) (index(hexadecimals, tolower(*colorstring++))
+        blue_value = (int) (index(hexadecimals, tolower((uchar) *colorstring))
                             - hexadecimals);
+        ++colorstring;
         blue_value *= 16;
-        blue_value += (int) (index(hexadecimals, tolower(*colorstring++))
+        blue_value += (int) (index(hexadecimals,
+                                   tolower((uchar) *colorstring))
                              - hexadecimals);
+        ++colorstring;
 
         *colorptr = RGB(red_value, green_value, blue_value);
     } else {