From 609f5c2256a1732668773b4138d1f39bcdc555b6 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 14 Jan 2018 00:22:30 +0000 Subject: [PATCH] plug the first couple of ctype bugs --- eval.c | 4 ++-- lex.c | 6 +++--- sh.h | 5 ++++- syn.c | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/eval.c b/eval.c index 645b7dc..4bcc2fe 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.217 2018/01/14 00:03:02 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.218 2018/01/14 00:22:27 tg Exp $"); /* * string expansion @@ -897,7 +897,7 @@ expand( --newlines; } else { while ((c = shf_getc(x.u.shf)) == 0 || - ctype(c, C_NL)) { + cinttype(c, C_NL)) { #ifdef MKSH_WITH_TEXTMODE if (c == '\r') { c = shf_getc(x.u.shf); diff --git a/lex.c b/lex.c index 88a5774..55ecbdd 100644 --- a/lex.c +++ b/lex.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.242 2018/01/14 00:03:02 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.243 2018/01/14 00:22:28 tg Exp $"); /* * states while lexing word @@ -248,7 +248,7 @@ yylex(int cf) /* collect non-special or quoted characters to form word */ while (!((c = getsc()) == 0 || - ((state == SBASE || state == SHEREDELIM) && ctype(c, C_LEX1)))) { + ((state == SBASE || state == SHEREDELIM) && cinttype(c, C_LEX1)))) { if (state == SBASE && subshell_nesting_type == ORD(/*{*/ '}') && (unsigned int)c == ORD(/*{*/ '}')) @@ -299,7 +299,7 @@ yylex(int cf) } /* FALLTHROUGH */ Sbase1: /* includes *(...|...) pattern (*+?@!) */ - if (ctype(c, C_PATMO)) { + if (cinttype(c, C_PATMO)) { c2 = getsc(); if ((unsigned int)c2 == ORD('(' /*)*/)) { *wp++ = OPAT; diff --git a/sh.h b/sh.h index d286d30..be151cb 100644 --- a/sh.h +++ b/sh.h @@ -182,7 +182,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.853 2018/01/14 00:09:34 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.854 2018/01/14 00:22:29 tg Exp $"); #endif #define MKSH_VERSION "R56 2017/10/17" @@ -1516,6 +1516,9 @@ extern void ebcdic_init(void); /* new fast character classes */ #define ctype(c,t) tobool(ksh_ctypes[ord(c)] & (t)) /* helper functions */ +#define cinttype(c,t) (intischar(c) ? \ + tobool(ksh_ctypes[(unsigned char)(c)] & (t)) : 0) +#define intischar(i) ((i) >= 0 && (i) <= 0xFF) #define ksh_isdash(s) tobool(ord((s)[0]) == '-' && ord((s)[1]) == '\0') /* invariant distance even in EBCDIC */ #define ksh_tolower(c) (ctype(c, C_UPPER) ? (c) - 'A' + 'a' : (c)) diff --git a/syn.c b/syn.c index 421cea3..e4c38e3 100644 --- a/syn.c +++ b/syn.c @@ -24,7 +24,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.126 2018/01/14 00:03:04 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.127 2018/01/14 00:22:30 tg Exp $"); struct nesting_state { int start_token; /* token than began nesting (eg, FOR) */ @@ -95,7 +95,7 @@ yyparse(bool doalias) c = tpeek(0); if (c == 0 && !outtree) outtree = newtp(TEOF); - else if (!ctype(c, C_LF | C_NUL)) + else if (!cinttype(c, C_LF | C_NUL)) syntaxerr(NULL); }