From 0cacf0d8726ffa74a679fdab26debbc0da00cc90 Mon Sep 17 00:00:00 2001 From: shmuz Date: Wed, 15 Dec 2010 15:28:01 +0200 Subject: 1. fix rex.split (offset was out-of-range) 2. PCRE: add new flags from PCRE 8.11 --- src/algo.h | 20 ++++++++++++-------- src/pcre/lpcre_f.c | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/algo.h b/src/algo.h index 2a4288d..a302d09 100644 --- a/src/algo.h +++ b/src/algo.h @@ -3,7 +3,7 @@ #include "common.h" -#define REX_VERSION "Lrexlib 2.5.1" +#define REX_VERSION "Lrexlib 2.5.3" /* Forward declarations */ static void gmatch_pushsubject (lua_State *L, TArgExec *argE); @@ -495,7 +495,9 @@ static int split_iter (lua_State *L) { if (argE.startoffset > (int)argE.textlen) return 0; - newoffset = argE.startoffset + incr; + if ((newoffset = argE.startoffset + incr) > (int)argE.textlen) + goto nomatch; + res = split_exec (ud, &argE, newoffset); if (ALG_ISMATCH (res)) { ALG_PUSHEND (L, ud, ALG_BASE(newoffset), 0); /* update start offset */ @@ -515,14 +517,16 @@ static int split_iter (lua_State *L) { return 2; } } - else if (ALG_NOMATCH (res)) { - lua_pushinteger (L, argE.textlen + 1); /* mark as last iteration */ - lua_replace (L, lua_upvalueindex (4)); /* update start offset */ - lua_pushlstring (L, argE.text+argE.startoffset, argE.textlen-argE.startoffset); - return 1; - } + else if (ALG_NOMATCH (res)) + goto nomatch; else return generate_error (L, ud, res); + +nomatch: + lua_pushinteger (L, argE.textlen + 1); /* mark as last iteration */ + lua_replace (L, lua_upvalueindex (4)); /* update start offset */ + lua_pushlstring (L, argE.text+argE.startoffset, argE.textlen-argE.startoffset); + return 1; } diff --git a/src/pcre/lpcre_f.c b/src/pcre/lpcre_f.c index 1862c0d..f032f94 100644 --- a/src/pcre/lpcre_f.c +++ b/src/pcre/lpcre_f.c @@ -164,6 +164,12 @@ flag_pair pcre_error_flags[] = { #ifdef PCRE_ERROR_NULLWSLIMIT { "ERROR_NULLWSLIMIT", PCRE_ERROR_NULLWSLIMIT }, #endif +#ifdef PCRE_ERROR_BADOFFSET + { "ERROR_BADOFFSET", PCRE_ERROR_BADOFFSET }, +#endif +#ifdef PCRE_ERROR_SHORTUTF8 + { "ERROR_SHORTUTF8", PCRE_ERROR_SHORTUTF8 }, +#endif /*---------------------------------------------------------------------------*/ { NULL, 0 } }; -- cgit v1.2.1