[winpr,collections] ListDictionary_GetKeys

This commit is contained in:
akallabeth 2023-06-27 09:32:00 +02:00 committed by akallabeth
parent ac39e8aac2
commit 63d4da2d0d
5 changed files with 22 additions and 27 deletions

View File

@ -144,16 +144,15 @@ DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32 id)
DEVICE* devman_get_device_by_type(DEVMAN* devman, UINT32 type)
{
DEVICE* device = NULL;
ULONG_PTR* keys;
int count, x;
ULONG_PTR* keys = NULL;
if (!devman)
return NULL;
ListDictionary_Lock(devman->devices);
count = ListDictionary_GetKeys(devman->devices, &keys);
const size_t count = ListDictionary_GetKeys(devman->devices, &keys);
for (x = 0; x < count; x++)
for (size_t x = 0; x < count; x++)
{
DEVICE* cur = (DEVICE*)ListDictionary_GetItemValue(devman->devices, (void*)keys[x]);

View File

@ -136,12 +136,11 @@ static BOOL device_foreach(rdpdrPlugin* rdpdr, BOOL abortOnFail,
BOOL (*fkt)(ULONG_PTR key, void* element, void* data), void* data)
{
BOOL rc = TRUE;
int count, x;
ULONG_PTR* keys = NULL;
ListDictionary_Lock(rdpdr->devman->devices);
count = ListDictionary_GetKeys(rdpdr->devman->devices, &keys);
for (x = 0; x < count; x++)
const size_t count = ListDictionary_GetKeys(rdpdr->devman->devices, &keys);
for (size_t x = 0; x < count; x++)
{
void* element = ListDictionary_GetItemValue(rdpdr->devman->devices, (void*)keys[x]);
if (!fkt(keys[x], element, data))

View File

@ -531,11 +531,10 @@ static void create_irp_thread(SERIAL_DEVICE* serial, IRP* irp)
/* Cleaning up termitating and pending irp
* threads. See also: irp_thread_func() */
HANDLE cirpThread;
ULONG_PTR* ids;
int i, nbIds;
nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
ULONG_PTR* ids = NULL;
const size_t nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
for (i = 0; i < nbIds; i++)
for (size_t i = 0; i < nbIds; i++)
{
/* Checking if ids[i] is terminating or pending */
DWORD waitResult;
@ -664,12 +663,13 @@ error_handle:
static void terminate_pending_irp_threads(SERIAL_DEVICE* serial)
{
ULONG_PTR* ids;
int i, nbIds;
nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
WLog_Print(serial->log, WLOG_DEBUG, "Terminating %d IRP thread(s)", nbIds);
WINPR_ASSERT(serial);
for (i = 0; i < nbIds; i++)
ULONG_PTR* ids = NULL;
const size_t nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
WLog_Print(serial->log, WLOG_DEBUG, "Terminating %" PRIuz " IRP thread(s)", nbIds);
for (size_t i = 0; i < nbIds; i++)
{
HANDLE irpThread;
ULONG_PTR id = ids[i];

View File

@ -227,7 +227,7 @@ extern "C"
WINPR_API void ListDictionary_Clear(wListDictionary* listDictionary);
WINPR_API BOOL ListDictionary_Contains(wListDictionary* listDictionary, const void* key);
WINPR_API int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys);
WINPR_API size_t ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys);
WINPR_API void* ListDictionary_GetItemValue(wListDictionary* listDictionary, const void* key);
WINPR_API BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, const void* key,

View File

@ -96,24 +96,21 @@ void ListDictionary_Unlock(wListDictionary* listDictionary)
* Gets the list of keys as an array
*/
int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
size_t ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
{
int index;
int count;
ULONG_PTR* pKeys = NULL;
wListDictionaryItem* item;
if (!ppKeys || !listDictionary)
return -1;
return 0;
if (listDictionary->synchronized)
EnterCriticalSection(&listDictionary->lock);
count = 0;
size_t count = 0;
if (listDictionary->head)
{
item = listDictionary->head;
wListDictionaryItem* item = listDictionary->head;
while (item)
{
@ -122,7 +119,7 @@ int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
}
}
if (count)
if (count > 0)
{
pKeys = (ULONG_PTR*)calloc(count, sizeof(ULONG_PTR));
@ -135,11 +132,11 @@ int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
}
}
index = 0;
size_t index = 0;
if (listDictionary->head)
{
item = listDictionary->head;
wListDictionaryItem* item = listDictionary->head;
while (item)
{