nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] pick character classes

2006-04-18 09:03:33
in late march, i wrote:
i noticed this afternoon that pick doesn't honor ranges in
character classes.  it treats the class "[a-z]" as three
characters ('a', 'z', and '-') instead of 26.  so i implemented it.

i have a followon patch to the first one i did.  this one fixes
an issue where a very long character-class range (128 or more
characters) causes negative indexing into the case-folding array.

i'll apply this sometime next week unless i hear otherwise.

paul
=---------------------
 paul fox, pgf@foxharp.boston.ma.us (arlington, ma, where it's 55.2 degrees)

cvs diff: Diffing .
Index: picksbr.c
===================================================================
RCS file: /sources/nmh/nmh/uip/picksbr.c,v
retrieving revision 1.10
diff -u -u -r1.10 picksbr.c
--- picksbr.c   31 Mar 2006 15:14:49 -0000      1.10
+++ picksbr.c   18 Apr 2006 15:38:26 -0000
@@ -575,7 +575,7 @@
 {
     register int c;
     int cclcnt;
-    register char *ep, *dp, *sp, *lastep = 0;
+    register unsigned char *ep, *dp, *sp, *lastep = 0;
 
     dp = (ep = n->n_expbuf) + sizeof n->n_expbuf;
     sp = astr;
@@ -614,7 +614,7 @@
            case '[': 
                *ep++ = CCL;
                *ep++ = 0;
-               cclcnt = 1;
+               cclcnt = 0;
                if ((c = *sp++) == '^') {
                    c = *sp++;
                    ep[-2] = NCCL;
@@ -639,6 +639,8 @@
                            goto cerror;
                    }
                } while ((c = *sp++) != ']');
+               if (cclcnt > 255)
+                   goto cerror;
                lastep[1] = cclcnt;
                continue;
 
@@ -744,14 +746,14 @@
 static int
 advance (char *alp, char *aep)
 {
-    register char *lp, *ep, *curlp;
+    register unsigned char *lp, *ep, *curlp;
 
-    lp = alp;
-    ep = aep;
+    lp = (unsigned char *)alp;
+    ep = (unsigned char *)aep;
     for (;;)
        switch (*ep++) {
            case CCHR: 
-               if (*ep++ == *lp++ || ep[-1] == cc[(unsigned char)lp[-1]])
+               if (*ep++ == *lp++ || ep[-1] == cc[lp[-1]])
                    continue;
                return 0;
 
@@ -770,14 +772,14 @@
 
            case CCL: 
                if (cclass (ep, *lp++, 1)) {
-                   ep += *ep;
+                   ep += *ep + 1;
                    continue;
                }
                return 0;
 
            case NCCL: 
                if (cclass (ep, *lp++, 0)) {
-                   ep += *ep;
+                   ep += *ep + 1;
                    continue;
                }
                return 0;
@@ -790,7 +792,7 @@
 
            case CCHR | STAR: 
                curlp = lp;
-               while (*lp++ == *ep || cc[(unsigned char)lp[-1]] == *ep)
+               while (*lp++ == *ep || cc[lp[-1]] == *ep)
                    continue;
                ep++;
                goto star;
@@ -800,7 +802,7 @@
                curlp = lp;
                while (cclass (ep, *lp++, ep[-1] == (CCL | STAR)))
                    continue;
-               ep += *ep;
+               ep += *ep + 1;
                goto star;
 
        star: 
@@ -819,19 +821,18 @@
 
 
 static int
-cclass (char *aset, int ac, int af)
+cclass (unsigned char *aset, int ac, int af)
 {
-    register int    n;
-    register char   c,
-                   *set;
+    register unsigned int    n;
+    register unsigned char   c, *set;
 
     set = aset;
     if ((c = ac) == 0)
        return (0);
 
     n = *set++;
-    while (--n)
-       if (*set++ == c || set[-1] == cc[(unsigned char)c])
+    while (n--)
+       if (*set++ == c || set[-1] == cc[c])
            return (af);
 
     return (!af);


_______________________________________________
Nmh-workers mailing list
Nmh-workers@nongnu.org
http://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [Nmh-workers] pick character classes, Paul Fox <=