From 9070015b406518e7215f04c0c17eb3cac3e9849b Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sat, 8 Jan 2005 22:05:09 +0000 Subject: [PATCH] fixing behaviour for xmlRegExecErrInfo in case of rollback Daniel * xmlregexp.c: fixing behaviour for xmlRegExecErrInfo in case of rollback Daniel --- ChangeLog | 5 +++++ xmlregexp.c | 30 ++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 456e34db..fb48f5d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jan 8 23:04:10 CET 2005 Daniel Veillard + + * xmlregexp.c: fixing behaviour for xmlRegExecErrInfo in case of + rollback + Fri Jan 7 14:54:51 CET 2005 Daniel Veillard * TODO: small update diff --git a/xmlregexp.c b/xmlregexp.c index 8755b4f6..6ef0d9eb 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -2738,6 +2738,7 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, xmlRegAtomPtr atom; int ret; int final = 0; + int progress = 1; if (exec == NULL) return(-1); @@ -3006,6 +3007,20 @@ xmlRegExecPushString(xmlRegExecCtxtPtr exec, const xmlChar *value, } if ((exec->transno != 0) || (exec->state->nbTrans == 0)) { rollback: + /* + * if we didn't yet rollback on the current input store + * the current state as the error state. + */ + if (progress) { + progress = 0; + if (exec->errString != NULL) + xmlFree(exec->errString); + exec->errString = xmlStrdup(value); + exec->errState = exec->state; + memcpy(exec->errCounts, exec->counts, + exec->comp->nbCounters * sizeof(int)); + } + /* * Failed to find a way out */ @@ -3019,21 +3034,19 @@ rollback: #endif } } + continue; progress: + progress = 1; continue; } if (exec->status == 0) { return(exec->state->type == XML_REGEXP_FINAL_STATE); } - if (exec->status < 0) { - if (exec->errString != NULL) - xmlFree(exec->errString); - exec->errString = xmlStrdup(value); - exec->errState = exec->state; #ifdef DEBUG_ERR + if (exec->status < 0) { testerr(exec); -#endif } +#endif return(exec->status); } @@ -3105,7 +3118,8 @@ xmlRegExecPushString2(xmlRegExecCtxtPtr exec, const xmlChar *value, * the parameter @values must point to an array of @nbval string pointers * on return nbval will contain the number of possible strings in that * state and the @values array will be updated with them. The string values - * returned will be freed with the @exec context. + * returned will be freed with the @exec context and don't need to be + * deallocated. * * Returns: 0 in case of success or -1 in case of error. */ @@ -3163,7 +3177,7 @@ xmlRegExecErrInfo(xmlRegExecCtxtPtr exec, const xmlChar **string, xmlRegCounterPtr counter; int count; - count = exec->counts[trans->counter]; + count = exec->errCounts[trans->counter]; counter = &exec->comp->counters[trans->counter]; if (count < counter->max) { values[*nbval] = (const xmlChar *) atom->valuep;