1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-21 14:53:44 +03:00

regexp: Simplify xmlRegAtomPush

This commit is contained in:
Nick Wellnhofer
2023-02-17 15:19:37 +01:00
parent 3cc900f098
commit bd33331bb9

View File

@@ -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;