summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-01-29 22:32:03 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-01-29 22:32:03 (GMT)
commitc6539f705204b2d9e3162304ac3a06c824ce5f39 (patch)
tree1a01d862af1db11482671e4cac014b79878cd9d7
parente059535b05f7310bf3bad4d53cb343ecfe6aa801 (diff)
downloadtcl-c6539f705204b2d9e3162304ac3a06c824ce5f39.zip
tcl-c6539f705204b2d9e3162304ac3a06c824ce5f39.tar.gz
tcl-c6539f705204b2d9e3162304ac3a06c824ce5f39.tar.bz2
Backout TIP #388 implementation, this part doesn't belong in 8.5
-rw-r--r--generic/regc_lex.c35
-rw-r--r--generic/regcomp.c2
-rw-r--r--generic/regcustom.h2
3 files changed, 12 insertions, 27 deletions
diff --git a/generic/regc_lex.c b/generic/regc_lex.c
index 16e3ae9..588932b 100644
--- a/generic/regc_lex.c
+++ b/generic/regc_lex.c
@@ -742,7 +742,6 @@ lexescape(
struct vars *v)
{
chr c;
- int i;
static const chr alert[] = {
CHR('a'), CHR('l'), CHR('e'), CHR('r'), CHR('t')
};
@@ -819,23 +818,18 @@ lexescape(
RETV(PLAIN, CHR('\t'));
break;
case CHR('u'):
- c = (uchr) lexdigits(v, 16, 1, 4);
+ c = lexdigits(v, 16, 4, 4);
if (ISERR()) {
FAILW(REG_EESCAPE);
}
RETV(PLAIN, c);
break;
case CHR('U'):
- i = lexdigits(v, 16, 1, 8);
+ c = lexdigits(v, 16, 8, 8);
if (ISERR()) {
FAILW(REG_EESCAPE);
}
- if (i > 0xFFFF) {
- /* TODO: output a Surrogate pair
- */
- i = 0xFFFD;
- }
- RETV(PLAIN, (uchr) i);
+ RETV(PLAIN, c);
break;
case CHR('v'):
RETV(PLAIN, CHR('\v'));
@@ -850,7 +844,7 @@ lexescape(
break;
case CHR('x'):
NOTE(REG_UUNPORT);
- c = (uchr) lexdigits(v, 16, 1, 2);
+ c = lexdigits(v, 16, 1, 255); /* REs >255 long outside spec */
if (ISERR()) {
FAILW(REG_EESCAPE);
}
@@ -872,7 +866,7 @@ lexescape(
case CHR('9'):
save = v->now;
v->now--; /* put first digit back */
- c = (uchr) lexdigits(v, 10, 1, 255); /* REs >255 long outside spec */
+ c = lexdigits(v, 10, 1, 255); /* REs >255 long outside spec */
if (ISERR()) {
FAILW(REG_EESCAPE);
}
@@ -899,15 +893,10 @@ lexescape(
case CHR('0'):
NOTE(REG_UUNPORT);
v->now--; /* put first digit back */
- c = (uchr) lexdigits(v, 8, 1, 3);
+ c = lexdigits(v, 8, 1, 3);
if (ISERR()) {
FAILW(REG_EESCAPE);
}
- if (c > 0xff) {
- /* out of range, so we handled one digit too much */
- v->now--;
- c >>= 3;
- }
RETV(PLAIN, c);
break;
default:
@@ -920,16 +909,16 @@ lexescape(
/*
- lexdigits - slurp up digits and return chr value
- ^ static int lexdigits(struct vars *, int, int, int);
+ ^ static chr lexdigits(struct vars *, int, int, int);
*/
-static int /* chr value; errors signalled via ERR */
+static chr /* chr value; errors signalled via ERR */
lexdigits(
struct vars *v,
int base,
int minlen,
int maxlen)
{
- int n;
+ uchr n; /* unsigned to avoid overflow misbehavior */
int len;
chr c;
int d;
@@ -937,10 +926,6 @@ lexdigits(
n = 0;
for (len = 0; len < maxlen && !ATEOS(); len++) {
- if (n > 0x10fff) {
- /* Stop when continuing would otherwise overflow */
- break;
- }
c = *v->now++;
switch (c) {
case CHR('0'): case CHR('1'): case CHR('2'): case CHR('3'):
@@ -973,7 +958,7 @@ lexdigits(
ERR(REG_EESCAPE);
}
- return n;
+ return (chr)n;
}
/*
diff --git a/generic/regcomp.c b/generic/regcomp.c
index 211cd70..bee35d0 100644
--- a/generic/regcomp.c
+++ b/generic/regcomp.c
@@ -79,7 +79,7 @@ static void lexnest(struct vars *, const chr *, const chr *);
static void lexword(struct vars *);
static int next(struct vars *);
static int lexescape(struct vars *);
-static int lexdigits(struct vars *, int, int, int);
+static chr lexdigits(struct vars *, int, int, int);
static int brenext(struct vars *, pchr);
static void skip(struct vars *);
static chr newline(NOPARMS);
diff --git a/generic/regcustom.h b/generic/regcustom.h
index 681b97d..c2583fa 100644
--- a/generic/regcustom.h
+++ b/generic/regcustom.h
@@ -89,7 +89,7 @@ typedef int celt; /* Type to hold chr, or NOCELT */
#define NOCELT (-1) /* Celt value which is not valid chr */
#define CHR(c) (UCHAR(c)) /* Turn char literal into chr literal */
#define DIGITVAL(c) ((c)-'0') /* Turn chr digit into its value */
-#if TCL_UTF_MAX > 4
+#if TCL_UTF_MAX > 3
#define CHRBITS 32 /* Bits in a chr; must not use sizeof */
#define CHR_MIN 0x00000000 /* Smallest and largest chr; the value */
#define CHR_MAX 0xffffffff /* CHR_MAX-CHR_MIN+1 should fit in uchr */