conf: virDomainDiskSourceFormat: check for srcpool presence correctly

As a guard against programming errors, one part of the condition
only dereferences srcpool if it exists, other one does not.

Move the check up one level so that it actually has a chance to do
something useful.

Fixes: 19b1c0d319
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Ján Tomko 2023-11-01 15:18:24 +01:00
parent 1fdca3083b
commit 66e84b8a95

View File

@ -22363,14 +22363,12 @@ virDomainDiskSourceFormat(virBuffer *buf,
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
if (src->type == VIR_STORAGE_TYPE_VOLUME) {
if (src->srcpool) {
virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool);
virBufferEscapeString(&attrBuf, " volume='%s'", src->srcpool->volume);
if (src->srcpool->mode)
virBufferAsprintf(&attrBuf, " mode='%s'",
virStorageSourcePoolModeTypeToString(src->srcpool->mode));
}
if (src->type == VIR_STORAGE_TYPE_VOLUME && src->srcpool) {
virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool);
virBufferEscapeString(&attrBuf, " volume='%s'", src->srcpool->volume);
if (src->srcpool->mode)
virBufferAsprintf(&attrBuf, " mode='%s'",
virStorageSourcePoolModeTypeToString(src->srcpool->mode));
if (flags & VIR_DOMAIN_DEF_FORMAT_VOLUME_TRANSLATED &&
src->srcpool->actualtype != VIR_STORAGE_TYPE_NONE) {