提交 46084f2a 编写于 作者: A Andrea Bolognani

conf: Improve virDomainChrTargetDefFormat()

Make the switch statement type-aware, avoid calling
virDomainChrTargetTypeToString() more than once and check its
return value before using it.
Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
上级 2cd323e3
...@@ -23954,7 +23954,7 @@ virDomainChrTargetDefFormat(virBufferPtr buf, ...@@ -23954,7 +23954,7 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
const char *targetType = virDomainChrTargetTypeToString(def->deviceType, const char *targetType = virDomainChrTargetTypeToString(def->deviceType,
def->targetType); def->targetType);
switch (def->deviceType) { switch ((virDomainChrDeviceType) def->deviceType) {
case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: { case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: {
if (!targetType) { if (!targetType) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
...@@ -24001,28 +24001,43 @@ virDomainChrTargetDefFormat(virBufferPtr buf, ...@@ -24001,28 +24001,43 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
} }
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
if (!targetType) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not format console target type"));
return -1;
}
virBufferAsprintf(buf, virBufferAsprintf(buf,
"<target type='%s' port='%d'/>\n", "<target type='%s' port='%d'/>\n",
virDomainChrTargetTypeToString(def->deviceType, targetType, def->target.port);
def->targetType),
def->target.port);
break; break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
if (!targetType) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not format serial target type"));
return -1;
}
if (def->targetType != VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE) { if (def->targetType != VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE) {
virBufferAsprintf(buf, virBufferAsprintf(buf,
"<target type='%s' port='%d'/>\n", "<target type='%s' port='%d'/>\n",
virDomainChrTargetTypeToString(def->deviceType, targetType,
def->targetType),
def->target.port); def->target.port);
break; break;
} }
ATTRIBUTE_FALLTHROUGH; ATTRIBUTE_FALLTHROUGH;
default: case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
virBufferAsprintf(buf, "<target port='%d'/>\n", virBufferAsprintf(buf, "<target port='%d'/>\n",
def->target.port); def->target.port);
break; break;
case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected char device type %d"),
def->deviceType);
return -1;
} }
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册