From 01b0c107b5a11afae8d56739ee91fcc156da1422 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 3 May 2017 21:50:33 +0000 Subject: [PATCH] we absolutely require unambiguous mapping between EBCDIC and extended ASCII to be able to provide a global stronly monotonous order for comparisons and bracket expression ranges --- shf.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/shf.c b/shf.c index 18e987d..0b54d1c 100644 --- a/shf.c +++ b/shf.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.93 2017/05/03 17:51:06 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.94 2017/05/03 21:50:33 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -1234,7 +1234,7 @@ ebcdic_init(void) { int i = 256; unsigned char t; - bool mapcache[128]; + bool mapcache[256]; while (i--) ebcdic_rtt_toascii[i] = i; @@ -1251,6 +1251,16 @@ ebcdic_init(void) i = 256; while (i--) { t = ebcdic_rtt_toascii[i]; + /* ensure unique round-trip capable mapping */ + if (mapcache[t]) { + write(2, "mksh: duplicate EBCDIC to ASCII mapping\n", 40); + exit(255); + } + /* + * since there are 256 input octets, this also ensures + * the other mapping direction is completely filled + */ + mapcache[t] = true; /* fill the complete round-trip map */ ebcdic_rtt_fromascii[t] = i; /* @@ -1264,14 +1274,9 @@ ebcdic_init(void) * an unsigned int, and or the raw unconverted EBCDIC * values with 0x01000000 instead. */ - if (t < 0x80U) { - if (mapcache[t]) { - write(2, "mksh: duplicate EBCDIC to ASCII mapping\n", 40); - exit(255); - } - mapcache[t] = true; + if (t < 0x80U) ebcdic_map[i] = (unsigned short)ord(t); - } else + else ebcdic_map[i] = (unsigned short)(0x100U | ord(i)); } if (ebcdic_rtt_toascii[0] || ebcdic_rtt_fromascii[0] || ebcdic_map[0]) {