[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LPEG bug?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 17 Jul 2015 09:35:16 -0300
> > The problem can be reduced to the following example:
> [...]
> > (I think there is a similar bug in repetitions, line 678, but I have to
> > recheck that.)
>
> Hi Roberto,
>
> Have you had a chance to follow up this and the outstanding LPEG bugs?
By follow up you mean the "similar bug in repetitions"? I checked, there
is no similar bug in repetitions.
> - http://lua-users.org/lists/lua-l/2015-05/msg00483.html
I missed that message completely. (I mean, I did not see it.) The fix
seems trivial (again, a stupid bug):
lptree.c, in function lp_behind:
TTree *tree;
TTree *tree1 = getpatt(L, 1, NULL);
int n = fixedlen(tree1);
- luaL_argcheck(L, n > 0, 1, "pattern may not have fixed length");
+ luaL_argcheck(L, n >= 0, 1, "pattern may not have fixed length");
luaL_argcheck(L, !hascaptures(tree1), 1, "pattern have captures");
luaL_argcheck(L, n <= MAXBEHIND, 1, "pattern too long to look behind");
tree = newroot1sib(L, TBehind);
> - http://lua-users.org/lists/lua-l/2015-05/msg00410.html
That one the fix is this:
lptree.c:
static TTree *newtree (lua_State *L, int len) {
size_t size = (len - 1) * sizeof(TTree) + sizeof(Pattern);
Pattern *p = (Pattern *)lua_newuserdata(L, size);
luaL_getmetatable(L, PATTERN_T);
+ lua_pushvalue(L, -1);
+ lua_setuservalue(L, -3);
lua_setmetatable(L, -2);
p->code = NULL; p->codesize = 0;
return p->tree;
(OK, I will do a new release with these fixes...)
-- Roberto