1. NCCRUNE was too large by sizeof(Reclass.end)/sizeof(Rune). use enum of NSPANS in to size Reclass.spans and NCCLASS to size Reprog.class. could use nelem(yyclassp->spans) and nelem(classp->class) instead, but that seems a tad confusing. 2. a too-large character class didn't compile correctly and did not yield an error. error out if character class is too large. 3. use NSPANS=128 and not NSPANS=64/2. Notes: Fri Jul 23 16:13:10 EDT 2010 geoff done at bit differently, partly to avoid adding new symbols to . Reference: /n/sources/patch/applied/regexpclass Date: Tue Dec 1 02:40:23 CET 2009 Signed-off-by: quanstro@quanstro.net Reviewed-by: geoff --- /sys/include/regexp.h Tue Dec 1 02:17:39 2009 +++ /sys/include/regexp.h Tue Dec 1 02:17:38 2009 @@ -1,6 +1,11 @@ #pragma src "/sys/src/libregexp" #pragma lib "libregexp.a" +enum { + NSPANS = 128, /* max rune ranges per character class */ + NCLASS = 16, /* max character classes per program */ +}; + typedef struct Resub Resub; typedef struct Reclass Reclass; typedef struct Reinst Reinst; @@ -27,7 +32,7 @@ */ struct Reclass{ Rune *end; - Rune spans[64]; + Rune spans[NSPANS*2]; }; /* @@ -52,7 +57,7 @@ */ struct Reprog{ Reinst *startinst; /* start pc */ - Reclass class[16]; /* .data */ + Reclass class[NCLASS]; /* .data */ Reinst firstinst[5]; /* .text */ }; --- /sys/src/libregexp/regcomp.h Tue Dec 1 02:17:46 2009 +++ /sys/src/libregexp/regcomp.h Tue Dec 1 02:17:44 2009 @@ -8,13 +8,6 @@ Resub m[NSUBEXP]; }; -/* max character classes per program */ -Reprog RePrOg; -#define NCLASS (sizeof(RePrOg.class)/sizeof(Reclass)) - -/* max rune ranges per character class */ -#define NCCRUNE (sizeof(Reclass)/sizeof(Rune)) - /* * Actions and Tokens (Reinst types) * --- /sys/src/libregexp/regcomp.c Tue Dec 1 02:17:54 2009 +++ /sys/src/libregexp/regcomp.c Tue Dec 1 02:17:52 2009 @@ -387,7 +387,7 @@ bldcclass(void) { int type; - Rune r[NCCRUNE]; + Rune r[NSPANS*2]; Rune *p, *ep, *np; Rune rune; int quoted; @@ -408,7 +408,11 @@ } /* parse class into a set of spans */ - for(; ep<&r[NCCRUNE];){ + for(;;){ + if(ep == r + nelem(r)){ + rcerror("class too large"); + return 0; + } if(rune == 0){ rcerror("malformed '[]'"); return 0;