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:
19
xmlregexp.c
19
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;
|
||||
|
Reference in New Issue
Block a user