From: PatR Date: Tue, 19 Jul 2016 12:40:09 +0000 (-0700) Subject: add '(uchar)' casts to ctype calls X-Git-Tag: NetHack-3.6.1_RC01~638 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d69f0787be29c7f02bee3ae4e9d6de23dfff0515;p=nethack add '(uchar)' casts to ctype calls 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. --- diff --git a/src/attrib.c b/src/attrib.c index 1eb709d22..5c80c5ed2 100644 --- a/src/attrib.c +++ b/src/attrib.c @@ -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) { diff --git a/sys/share/pcsys.c b/sys/share/pcsys.c index 47f74a717..085956c76 100644 --- a/sys/share/pcsys.c +++ b/sys/share/pcsys.c @@ -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; } diff --git a/sys/winnt/nh340key.c b/sys/winnt/nh340key.c index 7d64b3843..8d512142e 100644 --- a/sys/winnt/nh340key.c +++ b/sys/winnt/nh340key.c @@ -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'; diff --git a/sys/winnt/nhdefkey.c b/sys/winnt/nhdefkey.c index 258874e54..5f7390955 100644 --- a/sys/winnt/nhdefkey.c +++ b/sys/winnt/nhdefkey.c @@ -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 { diff --git a/sys/winnt/nhraykey.c b/sys/winnt/nhraykey.c index cae80ccd8..3b0a6ef04 100644 --- a/sys/winnt/nhraykey.c +++ b/sys/winnt/nhraykey.c @@ -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 */ diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index e95fe4f1d..892744432 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -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); } } diff --git a/util/makedefs.c b/util/makedefs.c index 6ae0cefc9..25614d8b2 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -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 { diff --git a/win/share/tiletext.c b/win/share/tiletext.c index 8d913f897..f2ee7bf03 100644 --- a/win/share/tiletext.c +++ b/win/share/tiletext.c @@ -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 diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 74cee9880..6c07b5081 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -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) { diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index e30a099b3..40b4791ef 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -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) { diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index b51488332..7247dbbb3 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -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 {