Date: Sun, 3 Jun 2018 17:03:56 +0000 (UTC) From: Piotr Pawel Stefaniak <pstef@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334568 - head/usr.bin/indent Message-ID: <201806031703.w53H3ufe001534@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pstef Date: Sun Jun 3 17:03:55 2018 New Revision: 334568 URL: https://svnweb.freebsd.org/changeset/base/334568 Log: indent(1): limit character classification functions' input to unsigned char Modified: head/usr.bin/indent/args.c head/usr.bin/indent/indent.c head/usr.bin/indent/io.c head/usr.bin/indent/lexi.c Modified: head/usr.bin/indent/args.c ============================================================================== --- head/usr.bin/indent/args.c Sun Jun 3 16:52:30 2018 (r334567) +++ head/usr.bin/indent/args.c Sun Jun 3 17:03:55 2018 (r334568) @@ -217,7 +217,7 @@ scan_profile(FILE *f) } else if (i == '/' && comment && p > buf && p[-1] == '*') { p = buf + comment - 1; comment = 0; - } else if (isspace(i)) { + } else if (isspace((unsigned char)i)) { if (p > buf && !comment) break; } else { @@ -321,7 +321,7 @@ found: break; case PRO_INT: - if (!isdigit(*param_start)) { + if (!isdigit((unsigned char)*param_start)) { need_param: errx(1, "%s: ``%s'' requires a parameter", option_source, p->p_name); } Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Sun Jun 3 16:52:30 2018 (r334567) +++ head/usr.bin/indent/indent.c Sun Jun 3 17:03:55 2018 (r334568) @@ -402,7 +402,7 @@ main(int argc, char **argv) * if there was a newline resulting from the "{" before, * it must be scanned now and ignored. */ - while (isspace((int)*buf_ptr)) { + while (isspace((unsigned char)*buf_ptr)) { if (++buf_ptr >= buf_end) fill_buffer(); if (*buf_ptr == '\n') @@ -429,7 +429,7 @@ main(int argc, char **argv) ps.search_brace = false; goto check_type; } - while (sc_end > save_com && isblank((int)sc_end[-1])) { + while (sc_end > save_com && isblank((unsigned char)sc_end[-1])) { sc_end--; } if (swallow_optional_blanklines || @@ -1070,7 +1070,7 @@ check_type: e_code = chfont(&bodyf, &keywordf, e_code); for (t_ptr = token; *t_ptr; ++t_ptr) { CHECK_SIZE_CODE; - *e_code++ = keywordf.allcaps && islower(*t_ptr) + *e_code++ = keywordf.allcaps && islower((unsigned char)*t_ptr) ? toupper(*t_ptr) : *t_ptr; } e_code = chfont(&keywordf, &bodyf, e_code); Modified: head/usr.bin/indent/io.c ============================================================================== --- head/usr.bin/indent/io.c Sun Jun 3 16:52:30 2018 (r334567) +++ head/usr.bin/indent/io.c Sun Jun 3 17:03:55 2018 (r334568) @@ -243,7 +243,7 @@ dump_line(void) cur_col = 1; ++ps.out_lines; } - while (e_com > com_st && isspace(e_com[-1])) + while (e_com > com_st && isspace((unsigned char)e_com[-1])) e_com--; (void)pad_output(cur_col, target); fwrite(com_st, e_com - com_st, 1, output); @@ -638,9 +638,9 @@ parsefont(struct fstate *f, const char *s0) memset(f, '\0', sizeof(*f)); while (*s) { - if (isdigit(*s)) + if (isdigit((unsigned char)*s)) f->size = f->size * 10 + *s - '0'; - else if (isupper(*s)) + else if (isupper((unsigned char)*s)) if (f->font[0]) f->font[1] = *s; else Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Sun Jun 3 16:52:30 2018 (r334567) +++ head/usr.bin/indent/lexi.c Sun Jun 3 17:03:55 2018 (r334568) @@ -173,13 +173,15 @@ lexi(struct parser_state *state) } /* Scan an alphanumeric token */ - if (chartype[(int)*buf_ptr] == alphanum || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { + if (chartype[*buf_ptr & 127] == alphanum || + (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) { /* * we have a character or number */ struct templ *p; - if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { + if (isdigit((unsigned char)*buf_ptr) || + (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) { enum base { BASE_2, BASE_8, BASE_10, BASE_16 }; @@ -193,7 +195,7 @@ lexi(struct parser_state *state) in_base = BASE_2; else if (buf_ptr[1] == 'x' || buf_ptr[1] == 'X') in_base = BASE_16; - else if (isdigit(buf_ptr[1])) + else if (isdigit((unsigned char)buf_ptr[1])) in_base = BASE_8; } switch (in_base) { @@ -215,7 +217,7 @@ lexi(struct parser_state *state) case BASE_16: *e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++; - while (isxdigit(*buf_ptr)) { + while (isxdigit((unsigned char)*buf_ptr)) { CHECK_SIZE_TOKEN; *e_token++ = *buf_ptr++; } @@ -230,7 +232,7 @@ lexi(struct parser_state *state) } CHECK_SIZE_TOKEN; *e_token++ = *buf_ptr++; - if (!isdigit(*buf_ptr) && *buf_ptr != '.') { + if (!isdigit((unsigned char)*buf_ptr) && *buf_ptr != '.') { if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp) break; else { @@ -264,7 +266,7 @@ lexi(struct parser_state *state) } } else - while (chartype[(int)*buf_ptr] == alphanum || *buf_ptr == BACKSLASH) { + while (chartype[*buf_ptr & 127] == alphanum || *buf_ptr == BACKSLASH) { /* fill_buffer() terminates buffer with newline */ if (*buf_ptr == BACKSLASH) { if (*(buf_ptr + 1) == '\n') { @@ -557,7 +559,7 @@ stop_lit: if (state->in_or_st) state->block_init = 1; #ifdef undef - if (chartype[*buf_ptr] == opchar) { /* we have two char assignment */ + if (chartype[*buf_ptr & 127] == opchar) { /* we have two char assignment */ e_token[-1] = *buf_ptr++; if ((e_token[-1] == '<' || e_token[-1] == '>') && e_token[-1] == *buf_ptr) *e_token++ = *buf_ptr++;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806031703.w53H3ufe001534>