]> git.ipfire.org Git - thirdparty/libvirt.git/commit
vbox: fix incorrect loop condition in vboxHostDeviceGetXMLDesc
authorRyota Ozaki <ozaki.ryota@gmail.com>
Sun, 1 Dec 2013 14:46:05 +0000 (23:46 +0900)
committerDaniel Veillard <veillard@redhat.com>
Mon, 2 Dec 2013 02:57:14 +0000 (10:57 +0800)
commit82b5dd23f30e54b7caa3b9d82f1e3819a803fda8
tree7f79c3cf1fd66a52f58d344c337e5173d6e2098f
parentd3572bb7b431a0890e4129cb6c7c557808304e45
vbox: fix incorrect loop condition in vboxHostDeviceGetXMLDesc

The fixed loop used logical OR to combine two conditions, however,
it is apparently incorrect and logical AND is correct.

We can fix it by replacing OR with AND, but this patch instead
fixes the problem by getting rid of the first conditional
statement: USBFilterCount < def->nhostdevs. It isn't needed
because USBFilterCount will never be greater than or equal to
def->nhostdevs.

def->nhostdevs is calculated in the following code
above the loop in question like this:

    for (i = 0; i < deviceFilters.count; i++) {
        PRBool active = PR_FALSE;
        IUSBDeviceFilter *deviceFilter = deviceFilters.items[i];

        deviceFilter->vtbl->GetActive(deviceFilter, &active);
        if (active) {
            def->nhostdevs++;
        }
    }

And the loop is constructed as like this:

    for (i = 0; (USBFilterCount < def->nhostdevs) || (i < deviceFilters.count); i++) {
        PRBool active                  = PR_FALSE;
(snip)
        deviceFilter->vtbl->GetActive(deviceFilter, &active);
        if (!active)
            continue;
(snip)
        USBFilterCount++;
    }

So def->nhostdevs is the number of active device filters and
USBFilterCount is counted up only when a device filter is active.
Thus, we can remove USBFilterCount < def->nhostdevs safely.

Reported-by: Laine Stump <laine@laine.org>
Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
src/vbox/vbox_tmpl.c