Bug#24712, regexp greedy recursing wasn't handling zero kid back-tracked
state nor re-setting parenCount correctly.
Added license junk for bug#15529 (continuing).
Fix type-mismatch warning in jsstr.c
Switched off DEBUG only use of fd_pow under Windows.
This commit is contained in:
rogerl%netscape.com 2000-02-03 00:44:03 +00:00
Родитель 699f297668
Коммит 1a7b6442d8
4 изменённых файлов: 54 добавлений и 11 удалений

Просмотреть файл

@ -134,12 +134,7 @@
extern double fd_atan2 __P((double, double));
extern double fd_copysign __P((double, double));
#ifdef DEBUG
extern double fd_pow __P((double, double));
#else
#define fd_pow pow
#endif
#elif defined IRIX

Просмотреть файл

@ -1,5 +1,38 @@
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/* -*- Mode: C; tab-width: 8 -*-
* Copyright (C) 1998 Netscape Communications Corporation, All Rights Reserved.
* Copyright (C) 1998-1999 Netscape Communications Corporation, All Rights Reserved.
*/
#ifndef jsmath_h___

Просмотреть файл

@ -1320,9 +1320,17 @@ static const jschar *greedyRecurse(GreedyState *grState, const jschar *cp, const
{
const jschar *kidMatch;
const jschar *match;
int num;
/*
* when the kid match fails, we reset the parencount and run any
* previously succesful kid in order to restablish it's paren
* contents.
*/
num = grState->state->parenCount;
kidMatch = matchRENodes(grState->state, grState->kid, grState->next, cp);
if (kidMatch == NULL) {
grState->state->parenCount = num;
if (previousKid != NULL)
matchRENodes(grState->state, grState->kid, grState->next, previousKid);
return matchRENodes(grState->state, grState->next, grState->stop, cp);
@ -1331,11 +1339,18 @@ static const jschar *greedyRecurse(GreedyState *grState, const jschar *cp, const
if (kidMatch == cp) return kidMatch; /* no point pursuing an empty match forever */
if ((grState->maxKid == 0) || (++grState->kidCount < grState->maxKid)) {
match = greedyRecurse(grState, kidMatch, cp);
--grState->kidCount;
if (match != NULL) return match;
--grState->kidCount;
grState->state->parenCount = num;
matchRENodes(grState->state, grState->kid, grState->next, cp);
}
matchRENodes(grState->state, grState->kid, grState->next, cp);
return matchRENodes(grState->state, grState->next, grState->stop, kidMatch);
match = matchRENodes(grState->state, grState->next, grState->stop, kidMatch);
if (match != NULL) return match;
/* No subsequent kid could complete; final backtrack attempt with zero kids */
grState->state->parenCount = num;
if (previousKid != NULL)
matchRENodes(grState->state, grState->kid, grState->next, previousKid);
return matchRENodes(grState->state, grState->next, grState->stop, cp);
}
}
@ -1664,7 +1679,7 @@ static const jschar *matchRENodes(MatchState *state, RENode *ren, RENode *stop,
if (kidMatch == NULL)
return NULL;
if ((ren->flags & RENODE_MINIMAL) == 0)
return matchGreedyKid(state, ren, stop, 1, cp, NULL);
return matchGreedyKid(state, ren, stop, 1, kidMatch, cp);
cp = matchNonGreedyKid(state, ren, 1, 0, kidMatch);
if (cp == NULL) return NULL;
break;

Просмотреть файл

@ -3908,7 +3908,7 @@ static JSBool decode(JSContext *cx, JSString *str, JSString *reservedSet, jsval
B = JS7_UNHEX(str->chars[k + 1]) * 16 + JS7_UNHEX(str->chars[k + 2]);
k += 2;
if (!(B & 0x80))
C = B;
C = (jschar)B;
else {
n = 1;
while (B & (0x80 >> n)) n++;