From: Hans Leidekker hans@codeweavers.com
There's a small chance that a device is added immediately after counting. --- dlls/wbemprox/builtin.c | 45 +++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index a2c21a2a6de..8f9eaea60f1 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -3161,46 +3161,43 @@ static enum fill_status fill_pnpentity( struct table *table, const struct expr * enum fill_status status = FILL_STATUS_UNFILTERED; HDEVINFO device_info_set; SP_DEVINFO_DATA devinfo = {0}; - DWORD idx; + UINT row = 0, offset = 0; + DWORD idx = 0; + + if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
device_info_set = SetupDiGetClassDevsW( NULL, NULL, NULL, DIGCF_ALLCLASSES|DIGCF_PRESENT ); + if (device_info_set == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
devinfo.cbSize = sizeof(devinfo); - - idx = 0; - while (SetupDiEnumDeviceInfo( device_info_set, idx++, &devinfo )) - { - /* noop */ - } - - resize_table( table, idx, sizeof(*rec) ); - table->num_rows = 0; - rec = (struct record_pnpentity *)table->data; - - idx = 0; while (SetupDiEnumDeviceInfo( device_info_set, idx++, &devinfo )) { WCHAR device_id[MAX_PATH]; - if (SetupDiGetDeviceInstanceIdW( device_info_set, &devinfo, device_id, - ARRAY_SIZE(device_id), NULL )) + if (SetupDiGetDeviceInstanceIdW( device_info_set, &devinfo, device_id, ARRAY_SIZE(device_id), NULL )) { - rec->device_id = wcsdup( device_id ); + if (!resize_table( table, row + 1, sizeof(*rec) )) + { + SetupDiDestroyDeviceInfoList( device_info_set ); + return FILL_STATUS_FAILED; + } + + rec = (struct record_pnpentity *)(table->data + offset); + rec->device_id = wcsdup( device_id ); rec->manufacturer = L"The Wine Project"; - rec->name = L"Wine PnP Device"; + rec->name = L"Wine PnP Device";
- table->num_rows++; - if (!match_row( table, table->num_rows - 1, cond, &status )) + if (!match_row( table, row, cond, &status )) free_row_values( table, row ); + else { - free_row_values( table, table->num_rows - 1 ); - table->num_rows--; + offset += sizeof(*rec); + row++; } - else - rec++; } } - SetupDiDestroyDeviceInfoList( device_info_set );
+ TRACE("created %u rows\n", row); + table->num_rows = row; return status; }