Signed-off-by: Hans Leidekker hans@codeweavers.com --- dlls/wbemprox/builtin.c | 45 ++++++++++++++++++-------------- dlls/wbemprox/class.c | 6 ++--- dlls/wbemprox/query.c | 12 ++++----- dlls/wbemprox/wbemprox_private.h | 1 + 4 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/dlls/wbemprox/builtin.c b/dlls/wbemprox/builtin.c index 06ade746a5..8c4ebe44b0 100644 --- a/dlls/wbemprox/builtin.c +++ b/dlls/wbemprox/builtin.c @@ -1251,6 +1251,7 @@ static UINT16 systemenclosure_chassistypes[] = }; static const struct array systemenclosure_chassistypes_array = { + sizeof(*systemenclosure_chassistypes), ARRAY_SIZE(systemenclosure_chassistypes), &systemenclosure_chassistypes }; @@ -2484,8 +2485,9 @@ static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list ) return NULL; } } - ret->count = count; - ret->ptr = ptr; + ret->elem_size = sizeof(*ptr); + ret->count = count; + ret->ptr = ptr; return ret; } static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list ) @@ -2517,8 +2519,9 @@ static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *li } if ((p = wcsrchr( ptr[i - 1], ':' ))) *p = 0; } - ret->count = count; - ret->ptr = ptr; + ret->elem_size = sizeof(*ptr); + ret->count = count; + ret->ptr = ptr; return ret; } static struct array *get_ipaddress( IP_ADAPTER_UNICAST_ADDRESS_LH *list ) @@ -2549,8 +2552,9 @@ static struct array *get_ipaddress( IP_ADAPTER_UNICAST_ADDRESS_LH *list ) return NULL; } } - ret->count = count; - ret->ptr = ptr; + ret->elem_size = sizeof(*ptr); + ret->count = count; + ret->ptr = ptr; return ret; } static struct array *get_ipsubnet( IP_ADAPTER_UNICAST_ADDRESS_LH *list ) @@ -2601,8 +2605,9 @@ static struct array *get_ipsubnet( IP_ADAPTER_UNICAST_ADDRESS_LH *list ) return NULL; } } - ret->count = count; - ret->ptr = ptr; + ret->elem_size = sizeof(*ptr); + ret->count = count; + ret->ptr = ptr; return ret; } static WCHAR *get_settingid( UINT32 index ) @@ -3458,20 +3463,20 @@ static WCHAR *get_accountname( LSA_TRANSLATED_NAME *name ) } static struct array *get_binaryrepresentation( PSID sid, UINT len ) { - struct array *array = heap_alloc( sizeof(struct array) ); - if (array) + struct array *ret; + UINT8 *ptr; + + if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL; + if (!(ptr = heap_alloc( len ))) { - UINT8 *ret = heap_alloc( len ); - if (ret) - { - memcpy( ret, sid, len ); - array->count = len; - array->ptr = ret; - return array; - } - heap_free( array ); + heap_free( ret ); + return NULL; } - return NULL; + memcpy( ptr, sid, len ); + ret->elem_size = sizeof(*ptr); + ret->count = len; + ret->ptr = ptr; + return ret; } static WCHAR *get_referenceddomainname( LSA_REFERENCED_DOMAIN_LIST *domain ) { diff --git a/dlls/wbemprox/class.c b/dlls/wbemprox/class.c index 042ebebdcd..943d5fed61 100644 --- a/dlls/wbemprox/class.c +++ b/dlls/wbemprox/class.c @@ -235,13 +235,11 @@ static struct record *create_record( struct table *table )
void destroy_array( struct array *array, CIMTYPE type ) { - UINT i, size; - + UINT i; if (!array) return; if (type == CIM_STRING || type == CIM_DATETIME || type == CIM_REFERENCE) { - size = get_type_size( type ); - for (i = 0; i < array->count; i++) heap_free( *(WCHAR **)((char *)array->ptr + i * size) ); + for (i = 0; i < array->count; i++) heap_free( *(WCHAR **)((char *)array->ptr + i * array->elem_size) ); } heap_free( array->ptr ); heap_free( array ); diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index 080329c14a..0165d2301b 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -765,7 +765,6 @@ VARTYPE to_vartype( CIMTYPE type ) SAFEARRAY *to_safearray( const struct array *array, CIMTYPE type ) { SAFEARRAY *ret; - UINT size = get_type_size( type ); VARTYPE vartype = to_vartype( type ); LONG i;
@@ -773,7 +772,7 @@ SAFEARRAY *to_safearray( const struct array *array, CIMTYPE type )
for (i = 0; i < array->count; i++) { - void *ptr = (char *)array->ptr + i * size; + void *ptr = (char *)array->ptr + i * array->elem_size; if (vartype == VT_BSTR) { BSTR str = SysAllocString( *(const WCHAR **)ptr ); @@ -951,23 +950,22 @@ static struct array *to_array( VARIANT *var, CIMTYPE *type ) LONG bound, i; VARTYPE vartype; CIMTYPE basetype; - UINT size;
if (SafeArrayGetVartype( V_ARRAY( var ), &vartype ) != S_OK) return NULL; if (!(basetype = to_cimtype( vartype ))) return NULL; if (SafeArrayGetUBound( V_ARRAY( var ), 1, &bound ) != S_OK) return NULL; if (!(ret = heap_alloc( sizeof(struct array) ))) return NULL;
- ret->count = bound + 1; - size = get_type_size( basetype ); - if (!(ret->ptr = heap_alloc_zero( ret->count * size ))) + ret->count = bound + 1; + ret->elem_size = get_type_size( basetype ); + if (!(ret->ptr = heap_alloc_zero( ret->count * ret->elem_size ))) { heap_free( ret ); return NULL; } for (i = 0; i < ret->count; i++) { - void *ptr = (char *)ret->ptr + i * size; + void *ptr = (char *)ret->ptr + i * ret->elem_size; if (vartype == VT_BSTR) { BSTR str; diff --git a/dlls/wbemprox/wbemprox_private.h b/dlls/wbemprox/wbemprox_private.h index cbf4c894f1..799bc80050 100644 --- a/dlls/wbemprox/wbemprox_private.h +++ b/dlls/wbemprox/wbemprox_private.h @@ -124,6 +124,7 @@ struct property
struct array { + UINT elem_size; UINT count; void *ptr; };