Refactored ArrayList_Add to conform to other functions

This commit is contained in:
Armin Novak
2021-05-17 09:53:55 +02:00
committed by akallabeth
parent 880c603c26
commit a1c8e4cf85
19 changed files with 30 additions and 28 deletions

View File

@@ -98,7 +98,7 @@ static UINT dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr,
if (ppListener)
*ppListener = (IWTSListener*)listener;
if (ArrayList_Add(dvcman->listeners, listener) < 0)
if (!ArrayList_Add(dvcman->listeners, listener))
return ERROR_INTERNAL_ERROR;
return CHANNEL_RC_OK;
}
@@ -129,9 +129,9 @@ static UINT dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const ch
{
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*)pEntryPoints)->dvcman;
if (ArrayList_Add(dvcman->plugin_names, _strdup(name)) < 0)
if (!ArrayList_Add(dvcman->plugin_names, _strdup(name)))
return ERROR_INTERNAL_ERROR;
if (ArrayList_Add(dvcman->plugins, pPlugin) < 0)
if (!ArrayList_Add(dvcman->plugins, pPlugin))
return ERROR_INTERNAL_ERROR;
WLog_DBG(TAG, "register_plugin: num_plugins %d", ArrayList_Count(dvcman->plugins));
@@ -502,7 +502,7 @@ static UINT dvcman_create_channel(drdynvcPlugin* drdynvc, IWTSVirtualChannelMana
}
channel->status = ERROR_NOT_CONNECTED;
if (ArrayList_Add(dvcman->channels, channel) < 0)
if (!ArrayList_Add(dvcman->channels, channel))
return ERROR_INTERNAL_ERROR;
ArrayList_Lock(dvcman->listeners);

View File

@@ -1238,7 +1238,7 @@ static int libusb_udev_isoch_transfer(IUDEVICE* idev, URBDRC_CHANNEL_CALLBACK* c
set_stream_id_for_buffer(iso_transfer, streamID);
libusb_set_iso_packet_lengths(iso_transfer, iso_packet_size);
if (ArrayList_Add(pdev->request_queue, iso_transfer) < 0)
if (!ArrayList_Add(pdev->request_queue, iso_transfer))
{
WLog_Print(urbdrc->log, WLOG_WARN,
"Failed to queue iso transfer, streamID %08" PRIx32 " already in use!",
@@ -1349,7 +1349,7 @@ static int libusb_udev_bulk_or_interrupt_transfer(IUDEVICE* idev, URBDRC_CHANNEL
set_stream_id_for_buffer(transfer, streamID);
if (ArrayList_Add(pdev->request_queue, transfer) < 0)
if (!ArrayList_Add(pdev->request_queue, transfer))
{
WLog_Print(urbdrc->log, WLOG_WARN,
"Failed to queue transfer, streamID %08" PRIx32 " already in use!", streamID);

View File

@@ -700,7 +700,7 @@ static BOOL urbdrc_udevman_register_devices(UDEVMAN* udevman, const char* device
return CHANNEL_RC_NO_MEMORY;
idpair->vid = id1;
idpair->pid = id2;
if (ArrayList_Add(udevman->hotplug_vid_pids, idpair) == -1)
if (!ArrayList_Add(udevman->hotplug_vid_pids, idpair))
{
free(idpair);
return CHANNEL_RC_NO_MEMORY;

View File

@@ -193,7 +193,7 @@ BOOL xf_event_action_script_init(xfContext* xfc)
strtok_s(buffer, "\n", &context);
xevent = _strdup(buffer);
if (!xevent || ArrayList_Add(xfc->xevents, xevent) < 0)
if (!xevent || !ArrayList_Add(xfc->xevents, xevent))
{
pclose(actionScript);
ArrayList_Free(xfc->xevents);

View File

@@ -90,7 +90,7 @@ static BOOL xf_keyboard_action_script_init(xfContext* xfc)
strtok_s(buffer, "\n", &context);
keyCombination = _strdup(buffer);
if (!keyCombination || ArrayList_Add(xfc->keyCombinations, keyCombination) < 0)
if (!keyCombination || !ArrayList_Add(xfc->keyCombinations, keyCombination))
{
ArrayList_Free(xfc->keyCombinations);
xfc->actionScriptExists = FALSE;

View File

@@ -266,7 +266,7 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
if (!clientCall)
goto fail;
if (ArrayList_Add(rpc->client->ClientCallList, clientCall) < 0)
if (!ArrayList_Add(rpc->client->ClientCallList, clientCall))
{
rpc_client_call_free(clientCall);
goto fail;
@@ -410,7 +410,7 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
length = auth_3_pdu->header.frag_length;
clientCall = rpc_client_call_new(auth_3_pdu->header.call_id, 0);
if (ArrayList_Add(rpc->client->ClientCallList, clientCall) >= 0)
if (ArrayList_Add(rpc->client->ClientCallList, clientCall))
{
status = rpc_in_channel_send_pdu(inChannel, buffer, length);
}

View File

@@ -950,7 +950,7 @@ BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
if (!clientCall)
goto fail;
if (ArrayList_Add(rpc->client->ClientCallList, clientCall) < 0)
if (!ArrayList_Add(rpc->client->ClientCallList, clientCall))
{
rpc_client_call_free(clientCall);
goto fail;

View File

@@ -1218,7 +1218,7 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
channel->channelId = InterlockedIncrement(&vcm->dvc_channel_id_seq);
if (ArrayList_Add(vcm->dynamicVirtualChannels, channel) < 0)
if (!ArrayList_Add(vcm->dynamicVirtualChannels, channel))
goto fail;
s = Stream_New(NULL, 64);

View File

@@ -276,7 +276,7 @@ static BOOL pf_modules_register_plugin(proxyPlugin* plugin_to_register)
plugin_to_register))
return FALSE;
if (ArrayList_Add(plugins_list, plugin_to_register) < 0)
if (!ArrayList_Add(plugins_list, plugin_to_register))
{
WLog_ERR(TAG, "[%s]: failed adding plugin to list: %s", __FUNCTION__,
plugin_to_register->name);
@@ -364,7 +364,7 @@ static BOOL pf_modules_load_module(const char* module_path)
}
/* save module handle for freeing the module later */
if (ArrayList_Add(handles_list, handle) < 0)
if (!ArrayList_Add(handles_list, handle))
{
WLog_ERR(TAG, "ArrayList_Add failed!");
return FALSE;

View File

@@ -348,7 +348,7 @@ static BOOL pf_server_initialize_peer_connection(freerdp_peer* peer)
server_receive_channel_data_original = peer->ReceiveChannelData;
peer->ReceiveChannelData = pf_server_receive_channel_data_hook;
if (ArrayList_Add(server->clients, pdata) < 0)
if (!ArrayList_Add(server->clients, pdata))
return FALSE;
CountdownEvent_AddCount(server->waitGroup, 1);

View File

@@ -184,7 +184,7 @@ static BOOL shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* clien
if (!(client->encoder = shadow_encoder_new(client)))
goto fail_encoder_new;
if (ArrayList_Add(server->clients, (void*)client) >= 0)
if (ArrayList_Add(server->clients, (void*)client))
return TRUE;
shadow_encoder_free(client->encoder);

View File

@@ -270,7 +270,7 @@ void* shadow_multiclient_get_subscriber(rdpShadowMultiClientEvent* event)
subscriber->ref = event;
subscriber->pleaseHandle = FALSE;
if (ArrayList_Add(event->subscribers, subscriber) < 0)
if (!ArrayList_Add(event->subscribers, subscriber))
goto out_free;
WLog_VRB(TAG, "Get subscriber %p. Wait event %d. %d clients.\n", (void*)subscriber,

View File

@@ -124,7 +124,7 @@ extern "C"
WINPR_API void ArrayList_Clear(wArrayList* arrayList);
WINPR_API BOOL ArrayList_Contains(wArrayList* arrayList, const void* obj);
WINPR_API int ArrayList_Add(wArrayList* arrayList, void* obj);
WINPR_API BOOL ArrayList_Add(wArrayList* arrayList, const void* obj);
WINPR_API BOOL ArrayList_Insert(wArrayList* arrayList, size_t index, const void* obj);
WINPR_API BOOL ArrayList_Remove(wArrayList* arrayList, const void* obj);

View File

@@ -360,7 +360,7 @@ static BOOL add_file_to_list(const char* local_name, const WCHAR* remote_name, w
if (!file)
return FALSE;
if (ArrayList_Add(files, file) < 0)
if (!ArrayList_Add(files, file))
{
free_posix_file(file);
return FALSE;

View File

@@ -688,7 +688,7 @@ HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD
baseSocket->serverfd = serverfd;
baseSocket->references = 0;
if (ArrayList_Add(g_NamedPipeServerSockets, baseSocket) < 0)
if (!ArrayList_Add(g_NamedPipeServerSockets, baseSocket))
{
free(baseSocket->name);
goto out;

View File

@@ -137,7 +137,7 @@ static BOOL InitializeThreadpool(PTP_POOL pool)
goto fail_create_threads;
}
if (ArrayList_Add(pool->Threads, thread) < 0)
if (!ArrayList_Add(pool->Threads, thread))
goto fail_create_threads;
}
@@ -242,7 +242,7 @@ BOOL winpr_SetThreadpoolThreadMinimum(PTP_POOL ptpp, DWORD cthrdMic)
return FALSE;
}
if (ArrayList_Add(ptpp->Threads, thread) < 0)
if (!ArrayList_Add(ptpp->Threads, thread))
return FALSE;
}

View File

@@ -269,9 +269,10 @@ BOOL ArrayList_Contains(wArrayList* arrayList, const void* obj)
* Adds an object to the end of the ArrayList.
*/
int ArrayList_Add(wArrayList* arrayList, void* obj)
BOOL ArrayList_Add(wArrayList* arrayList, const void* obj)
{
int index = -1;
size_t index;
BOOL rc = FALSE;
ArrayList_Lock_Conditional(arrayList);
@@ -280,11 +281,12 @@ int ArrayList_Add(wArrayList* arrayList, void* obj)
index = arrayList->size++;
ArrayList_SetItem(arrayList, index, obj);
rc = TRUE;
out:
ArrayList_Unlock_Conditional(arrayList);
return index;
return rc;
}
/*

View File

@@ -18,7 +18,7 @@ int TestArrayList(int argc, char* argv[])
for (index = 0; index < elemsToInsert; index++)
{
if (ArrayList_Add(arrayList, (void*)index) < 0)
if (!ArrayList_Add(arrayList, (void*)index))
return -1;
}

View File

@@ -191,7 +191,7 @@ ATOM WINAPI RegisterClassExA(CONST WNDCLASSEXA* lpwcx)
_lpwcx = CloneWindowClass(lpwcx);
return ArrayList_Add(g_WindowClasses, (void*)_lpwcx) >= 0;
return ArrayList_Add(g_WindowClasses, (void*)_lpwcx);
}
ATOM WINAPI RegisterClassExW(CONST WNDCLASSEXW* lpwcx)