[libvirt] [PATCH] qemu: Resolve Coverity DEADCODE
Michal Privoznik
mprivozn at redhat.com
Mon Apr 27 11:51:03 UTC 2015
On 27.04.2015 13:33, John Ferlan wrote:
> Coverity notes taht the switch() used to check 'connected' values has
s/taht/that/
> two DEADCODE paths (_DEFAULT & _LAST). Since 'connected' is a boolean
> it can only be one or the other (CONNECTED or DISCONNECTED), so it just
> seems pointless to use a switch to get "all" values. Convert to if-else
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
> src/qemu/qemu_driver.c | 14 +++-----------
> 1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 31cbccb..1c72844 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -4497,8 +4497,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
> goto endjob;
>
> if (STREQ_NULLABLE(dev.data.chr->target.name, "org.qemu.guest_agent.0")) {
> - switch (newstate) {
> - case VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED:
> + if (newstate == VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED) {
> if (!priv->agent) {
> if ((rc = qemuConnectAgent(driver, vm)) == -2)
> goto endjob;
> @@ -4506,20 +4505,13 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
> if (rc < 0)
> priv->agentError = true;
> }
> - break;
> -
> - case VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED:
> + } else {
> if (priv->agent) {
> qemuAgentClose(priv->agent);
> priv->agent = NULL;
> priv->agentError = false;
> }
> - break;
> -
> - case VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT:
> - case VIR_DOMAIN_CHR_DEVICE_STATE_LAST:
> - break;
Can't we just put coverity[dead_error_begin] or something similar here?
> - };
> + }
>
> if ((event = virDomainEventAgentLifecycleNewFromObj(vm, newstate,
> VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL)))
>
Michal
More information about the libvir-list
mailing list