1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-23 01:52:48 +03:00

tree: Report malloc failures

Fix many places where malloc failures aren't reported.

Make some API function return an error code. Changing the return type
from void to int is technically an ABI break but should be safe on most
platforms.

- xmlNodeSetContent
- xmlNodeSetContentLen
- xmlNodeAddContent
- xmlNodeAddContentLen
- xmlNodeSetBase

Introduce new API functions that return a separate error code if a
memory allocation fails.

- xmlNodeGetAttrValue
- xmlNodeGetBaseSafe
- xmlGetNsListSafe

Introduce private functions xmlTreeEnsureXMLDecl and xmlSplitQName4.

Don't report low-level errors to the global error handler.

Fix tree

Introduce xmlGetNsListSafe

Fix tree
This commit is contained in:
Nick Wellnhofer
2023-12-10 16:37:43 +01:00
parent e34a49b78e
commit aca16fb3d4
4 changed files with 767 additions and 525 deletions

View File

@@ -9,7 +9,7 @@ libxml2.debugMemory(1)
#
# Testing XML document serialization
#
doc = libxml2.parseDoc(
doc = libxml2.readDoc(
"""<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE test [
<!ELEMENT test (#PCDATA) >
@@ -17,10 +17,11 @@ doc = libxml2.parseDoc(
<!ATTLIST test abc:attr CDATA #FIXED "def" >
]>
<test />
""")
""", None, None, libxml2.XML_PARSE_DTDATTR)
elem = doc.getRootElement()
attr = elem.hasNsProp('attr', 'http://abc.org')
if attr == None or attr.serialize()[:-1] != """<!ATTLIST test abc:attr CDATA #FIXED "def">""":
print(attr.serialize())
if attr == None:
print("Failed to find defaulted attribute abc:attr")
sys.exit(1)