From 08d928171c2e18156eb3239bb198dae6bb817bad Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 28 Aug 2019 14:14:26 +0200 Subject: [PATCH] wbemprox: Avoid evaluating row conditions twice. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/wbemprox/builtin.c | 9 ++++++--- dlls/wbemprox/query.c | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index 75cdfc3ba3d..3d2a0679af2 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -3026,7 +3026,7 @@ static enum fill_status fill_printer( struct table *table, const struct expr *co WCHAR id[20]; EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count ); - if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED; + if (!count) return FILL_STATUS_UNFILTERED; if (!(info = heap_alloc( size ))) return FILL_STATUS_FAILED; if (!EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, (BYTE *)info, size, &size, &count )) @@ -3093,7 +3093,11 @@ static enum fill_status fill_process( struct table *table, const struct expr *co do { - if (!resize_table( table, row + 1, sizeof(*rec) )) goto done; + if (!resize_table( table, row + 1, sizeof(*rec) )) + { + status = FILL_STATUS_FAILED; + goto done; + } rec = (struct record_process *)(table->data + offset); rec->caption = heap_strdupW( entry.szExeFile ); @@ -3118,7 +3122,6 @@ static enum fill_status fill_process( struct table *table, const struct expr *co TRACE("created %u rows\n", row); table->num_rows = row; - status = FILL_STATUS_UNFILTERED; done: CloseHandle( snap ); diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index 0165d2301be..e00f067e9e6 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -404,13 +404,15 @@ HRESULT eval_cond( const struct table *table, UINT row, const struct expr *cond, HRESULT execute_view( struct view *view ) { UINT i, j = 0, len; + enum fill_status status = FILL_STATUS_UNFILTERED; if (!view->table) return S_OK; if (view->table->fill) { clear_table( view->table ); - view->table->fill( view->table, view->cond ); + status = view->table->fill( view->table, view->cond ); } + if (status == FILL_STATUS_FAILED) return WBEM_E_FAILED; if (!view->table->num_rows) return S_OK; len = min( view->table->num_rows, 16 ); @@ -429,7 +431,8 @@ HRESULT execute_view( struct view *view ) if (!(tmp = heap_realloc( view->result, len * sizeof(UINT) ))) return E_OUTOFMEMORY; view->result = tmp; } - if ((hr = eval_cond( view->table, i, view->cond, &val, &type )) != S_OK) return hr; + if (status == FILL_STATUS_FILTERED) val = 1; + else if ((hr = eval_cond( view->table, i, view->cond, &val, &type )) != S_OK) return hr; if (val) view->result[j++] = i; } view->count = j;