mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41: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
|
* Thankfully, libxml maps what looks like globals into
|
||||||
* thread-local uses, so we are thread-safe. */
|
* thread-local uses, so we are thread-safe. */
|
||||||
xmlIndentTreeOutput = 1;
|
xmlIndentTreeOutput = 1;
|
||||||
if (!(xmlbuf = xmlBufferCreate())) {
|
xmlbuf = virXMLBufferCreate();
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
|
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
|
||||||
virBufferGetIndent(buf) / 2, 1) < 0) {
|
virBufferGetIndent(buf) / 2, 1) < 0) {
|
||||||
|
@ -2513,10 +2513,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
|
|||||||
* Thankfully, libxml maps what looks like globals into
|
* Thankfully, libxml maps what looks like globals into
|
||||||
* thread-local uses, so we are thread-safe. */
|
* thread-local uses, so we are thread-safe. */
|
||||||
xmlIndentTreeOutput = 1;
|
xmlIndentTreeOutput = 1;
|
||||||
if (!(xmlbuf = xmlBufferCreate())) {
|
xmlbuf = virXMLBufferCreate();
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
|
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
|
||||||
virBufferGetIndent(buf) / 2, 1) < 0) {
|
virBufferGetIndent(buf) / 2, 1) < 0) {
|
||||||
|
@ -3531,6 +3531,7 @@ virVsockSetGuestCid;
|
|||||||
|
|
||||||
# util/virxml.h
|
# util/virxml.h
|
||||||
virParseScaledValue;
|
virParseScaledValue;
|
||||||
|
virXMLBufferCreate;
|
||||||
virXMLCheckIllegalChars;
|
virXMLCheckIllegalChars;
|
||||||
virXMLExtractNamespaceXML;
|
virXMLExtractNamespaceXML;
|
||||||
virXMLFormatElement;
|
virXMLFormatElement;
|
||||||
|
@ -941,12 +941,7 @@ char *
|
|||||||
virXMLNodeToString(xmlDocPtr doc,
|
virXMLNodeToString(xmlDocPtr doc,
|
||||||
xmlNodePtr node)
|
xmlNodePtr node)
|
||||||
{
|
{
|
||||||
g_autoptr(xmlBuffer) xmlbuf = NULL;
|
g_autoptr(xmlBuffer) xmlbuf = virXMLBufferCreate();
|
||||||
|
|
||||||
if (!(xmlbuf = xmlBufferCreate())) {
|
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xmlNodeDump(xmlbuf, doc, node, 0, 1) == 0) {
|
if (xmlNodeDump(xmlbuf, doc, node, 0, 1) == 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -1467,3 +1462,15 @@ virParseScaledValue(const char *xpath,
|
|||||||
*val = bytes;
|
*val = bytes;
|
||||||
return 1;
|
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 scale,
|
||||||
unsigned long long max,
|
unsigned long long max,
|
||||||
bool required);
|
bool required);
|
||||||
|
|
||||||
|
xmlBufferPtr
|
||||||
|
virXMLBufferCreate(void);
|
||||||
|
@ -771,7 +771,7 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
|
|||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
xmlCharEncodingHandlerPtr handler;
|
xmlCharEncodingHandlerPtr handler;
|
||||||
g_autoptr(xmlBuffer) input = NULL;
|
g_autoptr(xmlBuffer) input = NULL;
|
||||||
g_autoptr(xmlBuffer) utf8 = NULL;
|
g_autoptr(xmlBuffer) utf8 = virXMLBufferCreate();
|
||||||
|
|
||||||
handler = xmlFindCharEncodingHandler(encoding);
|
handler = xmlFindCharEncodingHandler(encoding);
|
||||||
|
|
||||||
@ -781,8 +781,7 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(input = xmlBufferCreateStatic((char *)string, strlen(string))) ||
|
if (!(input = xmlBufferCreateStatic((char *)string, strlen(string)))) {
|
||||||
!(utf8 = xmlBufferCreate())) {
|
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user