From bd33331bb987c768fa728958f5835a2bf38bd562 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 17 Feb 2023 15:19:37 +0100 Subject: [PATCH] regexp: Simplify xmlRegAtomPush --- xmlregexp.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/xmlregexp.c b/xmlregexp.c index 56cd8629..fc920569 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -1315,26 +1315,17 @@ xmlRegAtomPush(xmlRegParserCtxtPtr ctxt, xmlRegAtomPtr atom) { ERROR("atom push: atom is NULL"); return(-1); } - if (ctxt->maxAtoms == 0) { - ctxt->maxAtoms = 4; - ctxt->atoms = (xmlRegAtomPtr *) xmlMalloc(ctxt->maxAtoms * - sizeof(xmlRegAtomPtr)); - if (ctxt->atoms == NULL) { - xmlRegexpErrMemory(ctxt, "pushing atom"); - ctxt->maxAtoms = 0; - return(-1); - } - } else if (ctxt->nbAtoms >= ctxt->maxAtoms) { + if (ctxt->nbAtoms >= ctxt->maxAtoms) { + size_t newSize = ctxt->maxAtoms ? ctxt->maxAtoms * 2 : 4; xmlRegAtomPtr *tmp; - ctxt->maxAtoms *= 2; - tmp = (xmlRegAtomPtr *) xmlRealloc(ctxt->atoms, ctxt->maxAtoms * - sizeof(xmlRegAtomPtr)); + + tmp = xmlRealloc(ctxt->atoms, newSize * sizeof(xmlRegAtomPtr)); if (tmp == NULL) { xmlRegexpErrMemory(ctxt, "allocating counter"); - ctxt->maxAtoms /= 2; return(-1); } ctxt->atoms = tmp; + ctxt->maxAtoms = newSize; } atom->no = ctxt->nbAtoms; ctxt->atoms[ctxt->nbAtoms++] = atom;