From ecde15910ad0dbdf50b3af37e3c29d8d3f5717ac Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Wed, 28 Mar 2012 13:06:37 -0400 Subject: [PATCH] qemu: eliminate nested switch, simplify code qemuBuildHostNetStr had a switch-within-a-switch where both were looking at the same variable. This was apparently to take advantage of code common to three different cases (while also taking care of some code that was different). However, there were only 2 lines common to all, one of those can be eliminated by merging it into the virAsprintfs that are in each case. On top of that, all the extra empty cases cause Coverity complaints (because they are unreachable), but absence of the empty cases causes a compile error due to "enumeration value not handled in switch". The solution is to just make each toplevel case independent, folding in the common code to each. --- src/qemu/qemu_command.c | 55 ++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a6a7b063d3..f971a08cea 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2721,8 +2721,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_DIRECT: - virBufferAddLit(&buf, "tap"); - virBufferAsprintf(&buf, "%cfd=%s", type_sep, tapfd); + virBufferAsprintf(&buf, "tap%cfd=%s", type_sep, tapfd); type_sep = ','; is_tap = true; break; @@ -2742,40 +2741,28 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, break; case VIR_DOMAIN_NET_TYPE_CLIENT: + virBufferAsprintf(&buf, "socket%cconnect=%s:%d", + type_sep, + net->data.socket.address, + net->data.socket.port); + type_sep = ','; + break; + case VIR_DOMAIN_NET_TYPE_SERVER: + virBufferAsprintf(&buf, "socket%clisten=%s:%d", + type_sep, + net->data.socket.address, + net->data.socket.port); + type_sep = ','; + break; + case VIR_DOMAIN_NET_TYPE_MCAST: - virBufferAddLit(&buf, "socket"); - switch (netType) { - case VIR_DOMAIN_NET_TYPE_CLIENT: - virBufferAsprintf(&buf, "%cconnect=%s:%d", - type_sep, - net->data.socket.address, - net->data.socket.port); - break; - case VIR_DOMAIN_NET_TYPE_SERVER: - virBufferAsprintf(&buf, "%clisten=%s:%d", - type_sep, - net->data.socket.address, - net->data.socket.port); - break; - case VIR_DOMAIN_NET_TYPE_MCAST: - virBufferAsprintf(&buf, "%cmcast=%s:%d", - type_sep, - net->data.socket.address, - net->data.socket.port); - break; - case VIR_DOMAIN_NET_TYPE_USER: - case VIR_DOMAIN_NET_TYPE_ETHERNET: - case VIR_DOMAIN_NET_TYPE_NETWORK: - case VIR_DOMAIN_NET_TYPE_BRIDGE: - case VIR_DOMAIN_NET_TYPE_INTERNAL: - case VIR_DOMAIN_NET_TYPE_DIRECT: - case VIR_DOMAIN_NET_TYPE_HOSTDEV: - case VIR_DOMAIN_NET_TYPE_LAST: - break; - } - type_sep = ','; - break; + virBufferAsprintf(&buf, "socket%cmcast=%s:%d", + type_sep, + net->data.socket.address, + net->data.socket.port); + type_sep = ','; + break; case VIR_DOMAIN_NET_TYPE_USER: default: