lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all:
We have a lua program using lpeg to do some data validation job. The
input data is a customized data format expression and lot of data (all
in string format). The program parses the input data format expression
and generates a new lpeg pattern, which is then used to validate all the
data strings. The problem we encounted was for some complicated data
format expression, the generated lpeg pattern exceeds the buildin
pattern limit MAXPATTSIZE. After a quick glance into lpeg.c source code
I simply changed the MAXPATTSIZE to INT_MAX - 10 and two occusion of
"short" to "int". The patch is attached below. From my testing results,
the program runs well under this patch. I dont have deep understanding
of the lpeg implementation, so I write to this list asking if anyone can
confirm that is there any problem with this patch. Thanks!

--- lpeg.c 2009-05-21 21:42:09.000000000 +0800
+++ lpeg.c.new 2009-06-22 16:16:32.000000000 +0800
@@ -150,7 +150,7 @@
struct Inst {
byte code;
byte aux;
- short offset;
+ int offset;
} i;
PattFunc f;
byte buff[1];
@@ -187,14 +187,14 @@

typedef struct Capture {
const char *s; /* position */
- short idx;
+ int idx;
byte kind;
byte siz;
} Capture;


/* maximum size (in elements) for a pattern */
-#define MAXPATTSIZE (SHRT_MAX - 10)
+#define MAXPATTSIZE (INT_MAX - 10)


/* size (in elements) for an instruction plus extra l bytes */
@@ -2194,3 +2194,4 @@
return 1;
}

+