[libvirt] [PATCH] Fix warning about using an uninitialized next_unit value

Using an uninitialized value and a bool saying if the value is valid may confuse compilators. --- src/conf/domain_conf.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 46d49a2..6dc8cf3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3883,26 +3883,28 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt, virDomainDefPtr def, virDomainHostdevDefPtr hostdev) { - int next_unit; + int next_unit = 0; unsigned nscsi_controllers = 0; - bool found = false; int i; + int ret; if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) return -1; - for (i = 0; i < def->ncontrollers && !found; i++) { + for (i = 0; i < def->ncontrollers; i++) { if (def->controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) continue; nscsi_controllers++; - next_unit = virDomainControllerSCSINextUnit(def, - xmlopt->config.hasWideScsiBus ? - SCSI_WIDE_BUS_MAX_CONT_UNIT : - SCSI_NARROW_BUS_MAX_CONT_UNIT, - def->controllers[i]->idx); - if (next_unit >= 0) - found = true; + ret = virDomainControllerSCSINextUnit(def, + xmlopt->config.hasWideScsiBus ? + SCSI_WIDE_BUS_MAX_CONT_UNIT : + SCSI_NARROW_BUS_MAX_CONT_UNIT, + def->controllers[i]->idx); + if (ret >= 0) { + next_unit = ret; + break; + } } hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE; @@ -3912,7 +3914,7 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt, nscsi_controllers; hostdev->info->addr.drive.bus = 0; hostdev->info->addr.drive.target = 0; - hostdev->info->addr.drive.unit = found ? next_unit : 0; + hostdev->info->addr.drive.unit = next_unit; return 0; } -- 1.8.2.1

On 03/06/13 18:22, Jiri Denemark wrote:
Using an uninitialized value and a bool saying if the value is valid may confuse compilators. --- src/conf/domain_conf.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 46d49a2..6dc8cf3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3883,26 +3883,28 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt, virDomainDefPtr def, virDomainHostdevDefPtr hostdev) { - int next_unit; + int next_unit = 0; unsigned nscsi_controllers = 0; - bool found = false; int i; + int ret;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) return -1;
- for (i = 0; i < def->ncontrollers && !found; i++) { + for (i = 0; i < def->ncontrollers; i++) { if (def->controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) continue;
nscsi_controllers++; - next_unit = virDomainControllerSCSINextUnit(def, - xmlopt->config.hasWideScsiBus ? - SCSI_WIDE_BUS_MAX_CONT_UNIT : - SCSI_NARROW_BUS_MAX_CONT_UNIT, - def->controllers[i]->idx); - if (next_unit >= 0) - found = true; + ret = virDomainControllerSCSINextUnit(def, + xmlopt->config.hasWideScsiBus ? + SCSI_WIDE_BUS_MAX_CONT_UNIT : + SCSI_NARROW_BUS_MAX_CONT_UNIT, + def->controllers[i]->idx); + if (ret >= 0) { + next_unit = ret; + break; + } }
hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE; @@ -3912,7 +3914,7 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt, nscsi_controllers;
This statement still uses the bool variable "found": hostdev->info->addr.drive.controller = found ? def->controllers[i - 1]->idx : nscsi_controllers; And the controller index "i - 1" above should be changed to "i" instead. Since the second expression of the for loop was changed. Osier

On Mon, Jun 03, 2013 at 18:32:15 +0800, Osier Yang wrote:
On 03/06/13 18:22, Jiri Denemark wrote:
Using an uninitialized value and a bool saying if the value is valid may confuse compilators. ... This statement still uses the bool variable "found":
hostdev->info->addr.drive.controller = found ? def->controllers[i - 1]->idx : nscsi_controllers;
Heh, I should have looked at the compilation result before sending this patch :-) V2 is on the way. Jirka

Using an uninitialized value and a bool saying if the value is valid may confuse compilators. --- src/conf/domain_conf.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 46d49a2..21750ac 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3883,36 +3883,36 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt, virDomainDefPtr def, virDomainHostdevDefPtr hostdev) { - int next_unit; - unsigned nscsi_controllers = 0; - bool found = false; + int next_unit = 0; + unsigned controller = 0; int i; + int ret; if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) return -1; - for (i = 0; i < def->ncontrollers && !found; i++) { + for (i = 0; i < def->ncontrollers; i++) { if (def->controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) continue; - nscsi_controllers++; - next_unit = virDomainControllerSCSINextUnit(def, - xmlopt->config.hasWideScsiBus ? - SCSI_WIDE_BUS_MAX_CONT_UNIT : - SCSI_NARROW_BUS_MAX_CONT_UNIT, - def->controllers[i]->idx); - if (next_unit >= 0) - found = true; + controller++; + ret = virDomainControllerSCSINextUnit(def, + xmlopt->config.hasWideScsiBus ? + SCSI_WIDE_BUS_MAX_CONT_UNIT : + SCSI_NARROW_BUS_MAX_CONT_UNIT, + def->controllers[i]->idx); + if (ret >= 0) { + next_unit = ret; + controller = def->controllers[i]->idx; + break; + } } hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE; - - hostdev->info->addr.drive.controller = found ? - def->controllers[i - 1]->idx : - nscsi_controllers; + hostdev->info->addr.drive.controller = controller; hostdev->info->addr.drive.bus = 0; hostdev->info->addr.drive.target = 0; - hostdev->info->addr.drive.unit = found ? next_unit : 0; + hostdev->info->addr.drive.unit = next_unit; return 0; } -- 1.8.2.1

On 06/03/2013 01:56 PM, Jiri Denemark wrote:
Using an uninitialized value and a bool saying if the value is valid may confuse compilators. --- src/conf/domain_conf.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
ACK Jan

On Mon, Jun 03, 2013 at 14:34:22 +0200, Jano Tomko wrote:
On 06/03/2013 01:56 PM, Jiri Denemark wrote:
Using an uninitialized value and a bool saying if the value is valid may confuse compilators. --- src/conf/domain_conf.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
ACK
Pushed, thanks. Jirka
participants (3)
-
Jiri Denemark
-
Ján Tomko
-
Osier Yang