mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: xml: Add virXMLBufferCreate wrapper
'xmlBufferCreate' returns NULL only on allocation failure. Add a wrapper which will call 'abort()' in such case in a centralised spot. It doesn't make much sense to continue execution from here. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
7a0b625ea2
commit
2b0f2a0a07
@ -28691,10 +28691,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
|
||||
* Thankfully, libxml maps what looks like globals into
|
||||
* thread-local uses, so we are thread-safe. */
|
||||
xmlIndentTreeOutput = 1;
|
||||
if (!(xmlbuf = xmlBufferCreate())) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
xmlbuf = virXMLBufferCreate();
|
||||
|
||||
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
|
||||
virBufferGetIndent(buf) / 2, 1) < 0) {
|
||||
|
@ -2513,10 +2513,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
|
||||
* Thankfully, libxml maps what looks like globals into
|
||||
* thread-local uses, so we are thread-safe. */
|
||||
xmlIndentTreeOutput = 1;
|
||||
if (!(xmlbuf = xmlBufferCreate())) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
xmlbuf = virXMLBufferCreate();
|
||||
|
||||
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
|
||||
virBufferGetIndent(buf) / 2, 1) < 0) {
|
||||
|
@ -3531,6 +3531,7 @@ virVsockSetGuestCid;
|
||||
|
||||
# util/virxml.h
|
||||
virParseScaledValue;
|
||||
virXMLBufferCreate;
|
||||
virXMLCheckIllegalChars;
|
||||
virXMLExtractNamespaceXML;
|
||||
virXMLFormatElement;
|
||||
|
@ -941,12 +941,7 @@ char *
|
||||
virXMLNodeToString(xmlDocPtr doc,
|
||||
xmlNodePtr node)
|
||||
{
|
||||
g_autoptr(xmlBuffer) xmlbuf = NULL;
|
||||
|
||||
if (!(xmlbuf = xmlBufferCreate())) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
g_autoptr(xmlBuffer) xmlbuf = virXMLBufferCreate();
|
||||
|
||||
if (xmlNodeDump(xmlbuf, doc, node, 0, 1) == 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
@ -1467,3 +1462,15 @@ virParseScaledValue(const char *xpath,
|
||||
*val = bytes;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
xmlBufferPtr
|
||||
virXMLBufferCreate(void)
|
||||
{
|
||||
xmlBufferPtr ret;
|
||||
|
||||
if (!(ret = xmlBufferCreate()))
|
||||
abort();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -286,3 +286,6 @@ int virParseScaledValue(const char *xpath,
|
||||
unsigned long long scale,
|
||||
unsigned long long max,
|
||||
bool required);
|
||||
|
||||
xmlBufferPtr
|
||||
virXMLBufferCreate(void);
|
||||
|
@ -771,7 +771,7 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
|
||||
char *result = NULL;
|
||||
xmlCharEncodingHandlerPtr handler;
|
||||
g_autoptr(xmlBuffer) input = NULL;
|
||||
g_autoptr(xmlBuffer) utf8 = NULL;
|
||||
g_autoptr(xmlBuffer) utf8 = virXMLBufferCreate();
|
||||
|
||||
handler = xmlFindCharEncodingHandler(encoding);
|
||||
|
||||
@ -781,8 +781,7 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(input = xmlBufferCreateStatic((char *)string, strlen(string))) ||
|
||||
!(utf8 = xmlBufferCreate())) {
|
||||
if (!(input = xmlBufferCreateStatic((char *)string, strlen(string)))) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user