From: Ken Hornstein Date: Tue, 5 Feb 2013 18:01:09 +0000 (-0500) Subject: Start of the signed/unsigned char cleanup. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/0138ab0e9b1e8fa59be141338d599277095dec8c?ds=sidebyside;hp=2ba12fd3ce39f4f4bcb693f3e67e233294acb581 Start of the signed/unsigned char cleanup. --- diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 437c811c..4409e628 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -270,7 +270,7 @@ static struct ftable functable[] = { #define PUTC(c) do { NEW(FT_CHAR,0,0); fp->f_char = (c); } while (0) static char *format_string; -static unsigned char *usr_fstring; /* for CERROR */ +static char *usr_fstring; /* for CERROR */ #define CERROR(str) compile_error (str, cp) @@ -321,7 +321,7 @@ compile_error(char *str, char *cp) for (i = errpos-errctx; i < errpos; i++) { #ifdef LOCALE - if (iscntrl(usr_fstring[i])) + if (iscntrl((unsigned char) usr_fstring[i])) #else if (usr_fstring[i] < 32) #endif diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index b1370fb7..6cceff32 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -50,13 +50,24 @@ match (char *str, char *sub) #ifdef LOCALE while ((c1 = *sub)) { - c1 = (isalpha(c1) && isupper(c1)) ? tolower(c1) : c1; - while ((c2 = *str++) && c1 != ((isalpha(c2) && isupper(c2)) ? tolower(c2) : c2)) + c1 = (isascii((unsigned char) c1) && isalpha((unsigned char) c1) && + isupper((unsigned char) c1)) ? tolower((unsigned char) c1) : c1; + while ((c2 = *str++) && c1 != ((isascii((unsigned char) c2) && + isalpha((unsigned char) c2) && + isupper((unsigned char) c2)) ? + tolower((unsigned char) c2) : c2)) ; if (! c2) return 0; s1 = sub + 1; s2 = str; - while ((c1 = *s1++) && ((isalpha(c1) && isupper(c1)) ? tolower(c1) : c1) == ((isalpha(c2 =*s2++) && isupper(c2)) ? tolower(c2) : c2)) + while ((c1 = *s1++) && ((isascii((unsigned char) c1) && + isalpha((unsigned char) c1) && + isupper((unsigned char) c1)) ? + tolower(c1) : c1) == + ((isascii((unsigned char) (c2 =*s2++)) && + isalpha((unsigned char) c2) && + isupper((unsigned char) c2)) ? + tolower((unsigned char) c2) : c2)) ; if (! c1) return 1; @@ -169,7 +180,7 @@ cptrimmed(char **dest, char **ep, char *str, unsigned int wid, char fill, end--; /* isnctrl(), etc., take an int argument. Cygwin's ctype.h intentionally warns if they are passed a char. */ - c = *sp; + c = (unsigned char) *sp; if (iscntrl(c) || isspace(c)) { sp++; #endif @@ -266,7 +277,7 @@ cpstripped (char **dest, char **end, char *max, char *str) if (iswcntrl(wide_char) || iswspace(wide_char)) { str += char_len; #else /* MULTIBYTE_SUPPORT */ - int c = *str; + int c = (unsigned char) *str; len--; if (iscntrl(c) || isspace(c)) { str++; @@ -342,10 +353,8 @@ get_x400_comp (char *mbox, char *key, char *buffer, int buffer_len) struct format * fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) { - char *cp, *ep; - unsigned char *sp; - char *savestr = NULL; - unsigned char *str = NULL; + char *cp, *ep, *sp; + char *savestr = NULL, *str = NULL; char buffer[BUFSIZ], buffer2[BUFSIZ]; int i, c, ljust, n; int value = 0; @@ -592,12 +601,12 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) case FT_LS_TRIM: if (str) { - unsigned char *xp; + char *xp; strncpy(buffer, str, sizeof(buffer)); buffer[sizeof(buffer)-1] = '\0'; str = buffer; - while (isspace(*str)) + while (isspace((unsigned char) *str)) str++; ljust = 0; if ((i = fmt->f_width) < 0) { @@ -609,7 +618,7 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) str[i] = '\0'; xp = str; xp += strlen(str) - 1; - while (xp > str && isspace(*xp)) + while (xp > str && isspace((unsigned char) *xp)) *xp-- = '\0'; if (ljust && i > 0 && (int) strlen(str) > i) str += strlen(str) - i; @@ -905,8 +914,7 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) * (e.g., "To: ") */ { - unsigned char *lp; - char *lastb; + char *lp, *lastb; int indent, wid, len; lp = str; @@ -919,21 +927,22 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) adios(NULL, "putaddr -- num register (%d) must be greater " "than label width (%d)", value, indent); } - while( (c = *sp++) && cp < ep) - *cp++ = c; + while( (c = (unsigned char) *sp++) && cp < ep) + *cp++ = (char) c; while (len > wid) { /* try to break at a comma; failing that, break at a * space. */ lastb = 0; sp = lp + wid; - while (sp > lp && (c = *--sp) != ',') { + while (sp > lp && (c = (unsigned char) *--sp) != ',') { if (! lastb && isspace(c)) lastb = sp - 1; } if (sp == lp) { if (! (sp = lastb)) { sp = lp + wid - 1; - while (*sp && *sp != ',' && !isspace(*sp)) + while (*sp && *sp != ',' && + !isspace((unsigned char) *sp)) sp++; if (*sp != ',') sp--; @@ -942,7 +951,7 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat) len -= sp - lp + 1; while (cp < ep && lp <= sp) *cp++ = *lp++; - while (isspace(*lp)) + while (isspace((unsigned char) *lp)) lp++, len--; if (*lp) { if (cp < ep) diff --git a/sbr/m_atoi.c b/sbr/m_atoi.c index 174c4077..f05271f7 100644 --- a/sbr/m_atoi.c +++ b/sbr/m_atoi.c @@ -16,11 +16,11 @@ int m_atoi (char *str) { int i; - unsigned char *cp; + char *cp; for (i = 0, cp = str; *cp; cp++) { #ifdef LOCALE - if (!isdigit(*cp)) + if (!isdigit((unsigned char) *cp)) #else if (*cp < '0' || *cp > '9') #endif diff --git a/uip/sortm.c b/uip/sortm.c index 68132989..b8dc9684 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -70,8 +70,7 @@ int main (int argc, char **argv) { int i, msgnum; - unsigned char *cp; - char *maildir, *datesw = NULL; + char *cp, *maildir, *datesw = NULL; char *folder = NULL, buf[BUFSIZ], **argp; char **arguments; struct msgs_array msgs = { 0, 0, NULL }; @@ -141,7 +140,7 @@ main (int argc, char **argv) submajor++; /* sort subject-major */ continue; } - if (!isdigit(*cp) || !(datelimit = atoi(cp))) + if (!isdigit((unsigned char) *cp) || !(datelimit = atoi(cp))) adios (NULL, "impossible limit %s", cp); datelimit *= 60*60*24; continue; @@ -365,7 +364,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg) } for (compnum = 1;;) { int bufsz = sizeof buf; - switch (state = m_getfld (&gstate, nam, buf, &bufsz, in)) { + switch (state = m_getfld (&gstate, (unsigned char *) nam, + (unsigned char *) buf, &bufsz, in)) { case FLD: case FLDPLUS: compnum++; @@ -373,7 +373,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg) datecomp = add (buf, datecomp); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, nam, buf, &bufsz, in); + state = m_getfld (&gstate, (unsigned char *) nam, + (unsigned char *) buf, &bufsz, in); datecomp = add (buf, datecomp); } if (!subjsort || subjcomp) @@ -382,7 +383,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg) subjcomp = add (buf, subjcomp); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, nam, buf, &bufsz, in); + state = m_getfld (&gstate, (unsigned char *) nam, + (unsigned char *) buf, &bufsz, in); subjcomp = add (buf, subjcomp); } if (datecomp) @@ -391,7 +393,8 @@ get_fields (char *datesw, int msg, struct smsg *smsg) /* just flush this guy */ while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, nam, buf, &bufsz, in); + state = m_getfld (&gstate, (unsigned char *) nam, + (unsigned char *) buf, &bufsz, in); } } continue; @@ -446,14 +449,13 @@ get_fields (char *datesw, int msg, struct smsg *smsg) * leading "re:", everything but letters & smash * letters to lower case. */ - register char *cp, *cp2; - register unsigned char c; + register char *cp, *cp2, c; cp = subjcomp; cp2 = subjcomp; if (strcmp (subjsort, "subject") == 0) { while ((c = *cp)) { - if (! isspace(c)) { + if (! isspace((unsigned char) c)) { if(uprf(cp, "re:")) cp += 2; else @@ -464,8 +466,9 @@ get_fields (char *datesw, int msg, struct smsg *smsg) } while ((c = *cp++)) { - if (isalnum(c)) - *cp2++ = isupper(c) ? tolower(c) : c; + if (isascii((unsigned char) c) && isalnum((unsigned char) c)) + *cp2++ = isupper((unsigned char) c) ? + tolower((unsigned char) c) : c; } *cp2 = '\0';