Merge pull request #4938 from akallabeth/warning_fixes_master
Warning fixes and TSG abort condition fix
This commit is contained in:
commit
d9a4ae8310
@ -1758,7 +1758,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
}
|
||||
CommandLineSwitchCase(arg, "relax-order-checks")
|
||||
{
|
||||
settings->AllowUnanouncedOrdersFromServer = arg->Value;
|
||||
settings->AllowUnanouncedOrdersFromServer = enable;
|
||||
}
|
||||
CommandLineSwitchCase(arg, "restricted-admin")
|
||||
{
|
||||
@ -2055,7 +2055,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
}
|
||||
CommandLineSwitchCase(arg, "load-balance-info")
|
||||
{
|
||||
if (!copy_value(arg->Value, &settings->LoadBalanceInfo))
|
||||
if (!copy_value(arg->Value, (char**)&settings->LoadBalanceInfo))
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
|
||||
settings->LoadBalanceInfoLength = (UINT32) strlen((char*)
|
||||
|
@ -84,7 +84,7 @@ struct _http_response
|
||||
wStream* data;
|
||||
};
|
||||
|
||||
static char* string_strnstr(const char* str1, const char* str2, size_t slen)
|
||||
static char* string_strnstr(char* str1, const char* str2, size_t slen)
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
@ -110,10 +110,10 @@ static char* string_strnstr(const char* str1, const char* str2, size_t slen)
|
||||
str1--;
|
||||
}
|
||||
|
||||
return ((char*) str1);
|
||||
return str1;
|
||||
}
|
||||
|
||||
static BOOL strings_equals_nocase(void* obj1, void* obj2)
|
||||
static BOOL strings_equals_nocase(const void* obj1, const void* obj2)
|
||||
{
|
||||
if (!obj1 || !obj2)
|
||||
return FALSE;
|
||||
@ -362,7 +362,7 @@ static BOOL http_encode_print(wStream* s, const char* fmt, ...)
|
||||
{
|
||||
char* str;
|
||||
va_list ap;
|
||||
size_t length, used;
|
||||
int length, used;
|
||||
|
||||
if (!s || !fmt)
|
||||
return FALSE;
|
||||
@ -371,19 +371,19 @@ static BOOL http_encode_print(wStream* s, const char* fmt, ...)
|
||||
length = vsnprintf(NULL, 0, fmt, ap) + 1;
|
||||
va_end(ap);
|
||||
|
||||
if (!Stream_EnsureRemainingCapacity(s, length))
|
||||
if (!Stream_EnsureRemainingCapacity(s, (size_t)length))
|
||||
return FALSE;
|
||||
|
||||
str = (char*)Stream_Pointer(s);
|
||||
va_start(ap, fmt);
|
||||
used = vsnprintf(str, length, fmt, ap);
|
||||
used = vsnprintf(str, (size_t)length, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
/* Strip the trailing '\0' from the string. */
|
||||
if ((used + 1) != length)
|
||||
return FALSE;
|
||||
|
||||
Stream_Seek(s, used);
|
||||
Stream_Seek(s, (size_t)used);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -571,7 +571,7 @@ static BOOL http_response_parse_header_field(HttpResponse* response, const char*
|
||||
{
|
||||
char* separator = NULL;
|
||||
const char* authScheme = NULL;
|
||||
const char* authValue = NULL;
|
||||
char* authValue = NULL;
|
||||
separator = strchr(value, ' ');
|
||||
|
||||
if (separator)
|
||||
@ -746,7 +746,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
|
||||
const char* line = string_strnstr(buffer, "\r\n\r\n", position);
|
||||
|
||||
if (line)
|
||||
payloadOffset = (line - buffer) + 4;
|
||||
payloadOffset = (line - buffer) + 4UL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -756,7 +756,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
|
||||
char* buffer = (char*)Stream_Buffer(response->data);
|
||||
char* line = (char*) Stream_Buffer(response->data);
|
||||
|
||||
while ((line = string_strnstr(line, "\r\n", payloadOffset - (line - buffer) - 2)))
|
||||
while ((line = string_strnstr(line, "\r\n", payloadOffset - (line - buffer) - 2UL)))
|
||||
{
|
||||
line += 2;
|
||||
count++;
|
||||
@ -832,7 +832,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
|
||||
}
|
||||
|
||||
Stream_Seek(response->data, (size_t)status);
|
||||
response->BodyLength += status;
|
||||
response->BodyLength += (unsigned long)status;
|
||||
|
||||
if (response->BodyLength > RESPONSE_SIZE_LIMIT)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@
|
||||
#define TAG FREERDP_TAG("core.gateway.ntlm")
|
||||
|
||||
static wStream* rpc_ntlm_http_request(HttpContext* http, const char* method,
|
||||
int contentLength, SecBuffer* ntlmToken)
|
||||
int contentLength, const SecBuffer* ntlmToken)
|
||||
{
|
||||
wStream* s = NULL;
|
||||
HttpRequest* request = NULL;
|
||||
|
@ -838,6 +838,11 @@ void rpc_client_call_free(RpcClientCall* clientCall)
|
||||
free(clientCall);
|
||||
}
|
||||
|
||||
static void rpc_array_client_call_free(void* call)
|
||||
{
|
||||
rpc_client_call_free((RpcClientCall*)call);
|
||||
}
|
||||
|
||||
int rpc_in_channel_send_pdu(RpcInChannel* inChannel, BYTE* buffer, UINT32 length)
|
||||
{
|
||||
int status;
|
||||
@ -870,7 +875,6 @@ int rpc_in_channel_send_pdu(RpcInChannel* inChannel, BYTE* buffer, UINT32 length
|
||||
|
||||
BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum)
|
||||
{
|
||||
SECURITY_STATUS status;
|
||||
UINT32 offset;
|
||||
BYTE* buffer = NULL;
|
||||
UINT32 stub_data_pad;
|
||||
@ -1021,7 +1025,7 @@ static BOOL rpc_client_resolve_gateway(rdpSettings* settings, char** host, UINT1
|
||||
if (!result)
|
||||
return FALSE;
|
||||
|
||||
*host = freerdp_tcp_address_to_string(result->ai_addr, NULL);
|
||||
*host = freerdp_tcp_address_to_string((const struct sockaddr_storage*)result->ai_addr, NULL);
|
||||
freeaddrinfo(result);
|
||||
return TRUE;
|
||||
}
|
||||
@ -1068,7 +1072,7 @@ RpcClient* rpc_client_new(rdpContext* context, UINT32 max_recv_frag)
|
||||
if (!client->ClientCallList)
|
||||
goto fail;
|
||||
|
||||
ArrayList_Object(client->ClientCallList)->fnObjectFree = rpc_client_call_free;
|
||||
ArrayList_Object(client->ClientCallList)->fnObjectFree = rpc_array_client_call_free;
|
||||
return client;
|
||||
fail:
|
||||
rpc_client_free(client);
|
||||
|
@ -229,6 +229,22 @@ struct rdp_tsg
|
||||
TSG_PACKET_VERSIONCAPS packetVersionCaps;
|
||||
};
|
||||
|
||||
static BOOL tsg_stream_align(wStream* s, size_t align)
|
||||
{
|
||||
size_t pos;
|
||||
size_t offset = 0;
|
||||
|
||||
if (!s)
|
||||
return FALSE;
|
||||
|
||||
pos = Stream_GetPosition(s);
|
||||
|
||||
if ((pos % align) != 0)
|
||||
offset = align - pos % align;
|
||||
|
||||
return Stream_SafeSeek(s, offset);
|
||||
}
|
||||
|
||||
static BIO_METHOD* BIO_s_tsg(void);
|
||||
/**
|
||||
* RPC Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378623/
|
||||
@ -559,12 +575,8 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
||||
goto fail;
|
||||
|
||||
/* 4-byte alignment */
|
||||
{
|
||||
UINT32 offset = Stream_GetPosition(pdu->s);
|
||||
|
||||
if (!Stream_SafeSeek(pdu->s, rpc_offset_align(&offset, 4)))
|
||||
goto fail;
|
||||
}
|
||||
if (!tsg_stream_align(pdu->s, 4))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -600,13 +612,11 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
||||
Stream_Read_UINT16(pdu->s, versionCaps->minorVersion); /* MinorVersion (2 bytes) */
|
||||
Stream_Read_UINT16(pdu->s,
|
||||
versionCaps->quarantineCapabilities); /* QuarantineCapabilities (2 bytes) */
|
||||
/* 4-byte alignment */
|
||||
{
|
||||
UINT32 offset = Stream_Pointer(pdu->s);
|
||||
|
||||
if (!Stream_SafeSeek(pdu->s, rpc_offset_align(&offset, 4)))
|
||||
goto fail;
|
||||
}
|
||||
/* 4-byte alignment */
|
||||
if (!tsg_stream_align(pdu->s, 4))
|
||||
goto fail;
|
||||
|
||||
tsgCaps = (PTSG_PACKET_CAPABILITIES) calloc(1, sizeof(TSG_PACKET_CAPABILITIES));
|
||||
|
||||
if (!tsgCaps)
|
||||
@ -666,10 +676,10 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
||||
|
||||
case TSG_ASYNC_MESSAGE_REAUTH:
|
||||
{
|
||||
UINT32 offset = Stream_Pointer(pdu->s);
|
||||
if (!tsg_stream_align(pdu->s, 8))
|
||||
goto fail;
|
||||
|
||||
if (!Stream_SafeSeek(pdu->s, rpc_offset_align(&offset, 8) ||
|
||||
(Stream_GetRemainingLength(pdu->s) < 8)))
|
||||
if (Stream_GetRemainingLength(pdu->s) < 8)
|
||||
goto fail;
|
||||
|
||||
Stream_Seek_UINT64(pdu->s); /* TunnelContext (8 bytes) */
|
||||
@ -681,12 +691,8 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
{
|
||||
UINT32 offset = Stream_GetPosition(pdu->s);
|
||||
|
||||
if (!Stream_SafeSeek(pdu->s, rpc_offset_align(&offset, 4)))
|
||||
goto fail;
|
||||
}
|
||||
if (!tsg_stream_align(pdu->s, 4))
|
||||
goto fail;
|
||||
|
||||
/* TunnelContext (20 bytes) */
|
||||
if (Stream_GetRemainingLength(pdu->s) < 24)
|
||||
@ -736,12 +742,8 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
||||
goto fail;
|
||||
|
||||
/* 4-byte alignment */
|
||||
{
|
||||
UINT32 offset = Stream_GetPosition(pdu->s);
|
||||
|
||||
if (!Stream_SafeSeek(pdu->s, rpc_offset_align(&offset, 4)))
|
||||
goto fail;
|
||||
}
|
||||
if (!tsg_stream_align(pdu->s, 4))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -777,13 +779,10 @@ static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu,
|
||||
Stream_Read_UINT16(pdu->s, versionCaps->majorVersion); /* MinorVersion (2 bytes) */
|
||||
Stream_Read_UINT16(pdu->s,
|
||||
versionCaps->quarantineCapabilities); /* QuarantineCapabilities (2 bytes) */
|
||||
/* 4-byte alignment */
|
||||
{
|
||||
UINT32 offset = Stream_GetPosition(pdu->s);
|
||||
|
||||
if (!Stream_SafeSeek(pdu->s, rpc_offset_align(&offset, 4)))
|
||||
goto fail;
|
||||
}
|
||||
/* 4-byte alignment */
|
||||
if (!tsg_stream_align(pdu->s, 4))
|
||||
goto fail;
|
||||
|
||||
if (Stream_GetRemainingLength(pdu->s) < 36)
|
||||
goto fail;
|
||||
@ -839,7 +838,7 @@ static BOOL TsProxyAuthorizeTunnelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunn
|
||||
count = _wcslen(tsg->MachineName) + 1;
|
||||
rpc = tsg->rpc;
|
||||
WLog_DBG(TAG, "TsProxyAuthorizeTunnelWriteRequest");
|
||||
s = Stream_New(NULL, 1024);
|
||||
s = Stream_New(NULL, 1024 + count * 2);
|
||||
|
||||
if (!s)
|
||||
return FALSE;
|
||||
@ -1727,10 +1726,10 @@ BOOL tsg_recv_pdu(rdpTsg* tsg, RPC_PDU* pdu)
|
||||
|
||||
BOOL tsg_check_event_handles(rdpTsg* tsg)
|
||||
{
|
||||
if (!rpc_client_in_channel_recv(tsg->rpc))
|
||||
if (rpc_client_in_channel_recv(tsg->rpc) < 0)
|
||||
return FALSE;
|
||||
|
||||
if (!rpc_client_out_channel_recv(tsg->rpc))
|
||||
if (rpc_client_out_channel_recv(tsg->rpc) < 0)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
@ -1199,7 +1199,7 @@ int freerdp_tcp_connect(rdpContext* context, rdpSettings* settings,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((peerAddress = freerdp_tcp_address_to_string((struct sockaddr_storage*)addr->ai_addr,
|
||||
if ((peerAddress = freerdp_tcp_address_to_string((const struct sockaddr_storage*)addr->ai_addr,
|
||||
NULL)) != NULL)
|
||||
{
|
||||
WLog_DBG(TAG, "connecting to peer %s", peerAddress);
|
||||
|
@ -574,7 +574,7 @@ static BOOL gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
|
||||
gdi_rop3_code(dstblt->bRop), &gdi->palette);
|
||||
}
|
||||
|
||||
static BOOL gdi_patblt(rdpContext* context, const PATBLT_ORDER* patblt)
|
||||
static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
|
||||
{
|
||||
const rdpBrush* brush = &patblt->brush;
|
||||
UINT32 foreColor;
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "sf_audin.h"
|
||||
|
||||
#include <freerdp/server/server-common.h>
|
||||
#include <freerdp/log.h>
|
||||
#define TAG SERVER_TAG("sample")
|
||||
|
||||
@ -61,10 +62,11 @@ static UINT sf_peer_audin_open_result(audin_server_context* context, UINT32 resu
|
||||
*
|
||||
* @return 0 on success, otherwise a Win32 error code
|
||||
*/
|
||||
static UINT sf_peer_audin_receive_samples(audin_server_context* context, const void* buf,
|
||||
int nframes)
|
||||
static UINT sf_peer_audin_receive_samples(audin_server_context* context,
|
||||
const AUDIO_FORMAT* format, wStream* buf,
|
||||
size_t nframes)
|
||||
{
|
||||
WLog_DBG(TAG, "AUDIN receive %d frames.", nframes);
|
||||
WLog_DBG(TAG, "AUDIN receive %"PRIdz" frames.", nframes);
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ typedef void* (*OBJECT_NEW_FN)();
|
||||
typedef void (*OBJECT_INIT_FN)(void* obj);
|
||||
typedef void (*OBJECT_UNINIT_FN)(void* obj);
|
||||
typedef void (*OBJECT_FREE_FN)(void* obj);
|
||||
typedef BOOL (*OBJECT_EQUALS_FN)(void* objA, void* objB);
|
||||
typedef BOOL (*OBJECT_EQUALS_FN)(const void* objA, const void* objB);
|
||||
|
||||
struct _wObject
|
||||
{
|
||||
@ -208,16 +208,17 @@ WINPR_API int ListDictionary_Count(wListDictionary* listDictionary);
|
||||
WINPR_API void ListDictionary_Lock(wListDictionary* listDictionary);
|
||||
WINPR_API void ListDictionary_Unlock(wListDictionary* listDictionary);
|
||||
|
||||
WINPR_API BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value);
|
||||
WINPR_API void* ListDictionary_Remove(wListDictionary* listDictionary, void* key);
|
||||
WINPR_API BOOL ListDictionary_Add(wListDictionary* listDictionary, const void* key, void* value);
|
||||
WINPR_API void* ListDictionary_Remove(wListDictionary* listDictionary, const void* key);
|
||||
WINPR_API void* ListDictionary_Remove_Head(wListDictionary* listDictionary);
|
||||
WINPR_API void ListDictionary_Clear(wListDictionary* listDictionary);
|
||||
|
||||
WINPR_API BOOL ListDictionary_Contains(wListDictionary* listDictionary, void* key);
|
||||
WINPR_API BOOL ListDictionary_Contains(wListDictionary* listDictionary, const void* key);
|
||||
WINPR_API int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys);
|
||||
|
||||
WINPR_API void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key);
|
||||
WINPR_API BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, void* value);
|
||||
WINPR_API void* ListDictionary_GetItemValue(wListDictionary* listDictionary, const void* key);
|
||||
WINPR_API BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, const void* key,
|
||||
void* value);
|
||||
|
||||
WINPR_API wListDictionary* ListDictionary_New(BOOL synchronized);
|
||||
WINPR_API void ListDictionary_Free(wListDictionary* listDictionary);
|
||||
|
@ -269,10 +269,10 @@ static BOOL reset_event(WINPR_THREAD* thread)
|
||||
return status;
|
||||
}
|
||||
|
||||
static BOOL thread_compare(void* a, void* b)
|
||||
static BOOL thread_compare(const void* a, const void* b)
|
||||
{
|
||||
pthread_t* p1 = a;
|
||||
pthread_t* p2 = b;
|
||||
const pthread_t* p1 = a;
|
||||
const pthread_t* p2 = b;
|
||||
BOOL rc = pthread_equal(*p1, *p2);
|
||||
return rc;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@
|
||||
* Gets or sets the number of elements that the ArrayList can contain.
|
||||
*/
|
||||
|
||||
int ArrayList_Capacity(wArrayList *arrayList)
|
||||
int ArrayList_Capacity(wArrayList* arrayList)
|
||||
{
|
||||
return arrayList->capacity;
|
||||
}
|
||||
@ -47,7 +47,7 @@ int ArrayList_Capacity(wArrayList *arrayList)
|
||||
* Gets the number of elements actually contained in the ArrayList.
|
||||
*/
|
||||
|
||||
int ArrayList_Count(wArrayList *arrayList)
|
||||
int ArrayList_Count(wArrayList* arrayList)
|
||||
{
|
||||
return arrayList->size;
|
||||
}
|
||||
@ -66,7 +66,7 @@ int ArrayList_Items(wArrayList* arrayList, ULONG_PTR** ppItems)
|
||||
* Gets a value indicating whether the ArrayList has a fixed size.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_IsFixedSized(wArrayList *arrayList)
|
||||
BOOL ArrayList_IsFixedSized(wArrayList* arrayList)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@ -75,7 +75,7 @@ BOOL ArrayList_IsFixedSized(wArrayList *arrayList)
|
||||
* Gets a value indicating whether the ArrayList is read-only.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_IsReadOnly(wArrayList *arrayList)
|
||||
BOOL ArrayList_IsReadOnly(wArrayList* arrayList)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@ -84,7 +84,7 @@ BOOL ArrayList_IsReadOnly(wArrayList *arrayList)
|
||||
* Gets a value indicating whether access to the ArrayList is synchronized (thread safe).
|
||||
*/
|
||||
|
||||
BOOL ArrayList_IsSynchronized(wArrayList *arrayList)
|
||||
BOOL ArrayList_IsSynchronized(wArrayList* arrayList)
|
||||
{
|
||||
return arrayList->synchronized;
|
||||
}
|
||||
@ -93,7 +93,7 @@ BOOL ArrayList_IsSynchronized(wArrayList *arrayList)
|
||||
* Lock access to the ArrayList
|
||||
*/
|
||||
|
||||
void ArrayList_Lock(wArrayList *arrayList)
|
||||
void ArrayList_Lock(wArrayList* arrayList)
|
||||
{
|
||||
EnterCriticalSection(&arrayList->lock);
|
||||
}
|
||||
@ -102,7 +102,7 @@ void ArrayList_Lock(wArrayList *arrayList)
|
||||
* Unlock access to the ArrayList
|
||||
*/
|
||||
|
||||
void ArrayList_Unlock(wArrayList *arrayList)
|
||||
void ArrayList_Unlock(wArrayList* arrayList)
|
||||
{
|
||||
LeaveCriticalSection(&arrayList->lock);
|
||||
}
|
||||
@ -111,9 +111,9 @@ void ArrayList_Unlock(wArrayList *arrayList)
|
||||
* Gets the element at the specified index.
|
||||
*/
|
||||
|
||||
void *ArrayList_GetItem(wArrayList *arrayList, int index)
|
||||
void* ArrayList_GetItem(wArrayList* arrayList, int index)
|
||||
{
|
||||
void *obj = NULL;
|
||||
void* obj = NULL;
|
||||
|
||||
if ((index >= 0) && (index < arrayList->size))
|
||||
{
|
||||
@ -127,7 +127,7 @@ void *ArrayList_GetItem(wArrayList *arrayList, int index)
|
||||
* Sets the element at the specified index.
|
||||
*/
|
||||
|
||||
void ArrayList_SetItem(wArrayList *arrayList, int index, void *obj)
|
||||
void ArrayList_SetItem(wArrayList* arrayList, int index, void* obj)
|
||||
{
|
||||
if ((index >= 0) && (index < arrayList->size))
|
||||
{
|
||||
@ -143,15 +143,15 @@ void ArrayList_SetItem(wArrayList *arrayList, int index, void *obj)
|
||||
* Shift a section of the list.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_Shift(wArrayList *arrayList, int index, int count)
|
||||
BOOL ArrayList_Shift(wArrayList* arrayList, int index, int count)
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
if (arrayList->size + count > arrayList->capacity)
|
||||
{
|
||||
void **newArray;
|
||||
void** newArray;
|
||||
int newCapacity = arrayList->capacity * arrayList->growthFactor;
|
||||
newArray = (void **)realloc(arrayList->array, sizeof(void *) * newCapacity);
|
||||
newArray = (void**)realloc(arrayList->array, sizeof(void*) * newCapacity);
|
||||
|
||||
if (!newArray)
|
||||
return FALSE;
|
||||
@ -160,7 +160,8 @@ BOOL ArrayList_Shift(wArrayList *arrayList, int index, int count)
|
||||
arrayList->capacity = newCapacity;
|
||||
}
|
||||
|
||||
MoveMemory(&arrayList->array[index + count], &arrayList->array[index], (arrayList->size - index) * sizeof(void *));
|
||||
MoveMemory(&arrayList->array[index + count], &arrayList->array[index],
|
||||
(arrayList->size - index) * sizeof(void*));
|
||||
arrayList->size += count;
|
||||
}
|
||||
else if (count < 0)
|
||||
@ -168,7 +169,7 @@ BOOL ArrayList_Shift(wArrayList *arrayList, int index, int count)
|
||||
int chunk = arrayList->size - index + count;
|
||||
|
||||
if (chunk > 0)
|
||||
MoveMemory(&arrayList->array[index], &arrayList->array[index - count], chunk * sizeof(void *));
|
||||
MoveMemory(&arrayList->array[index], &arrayList->array[index - count], chunk * sizeof(void*));
|
||||
|
||||
arrayList->size += count;
|
||||
}
|
||||
@ -180,7 +181,7 @@ BOOL ArrayList_Shift(wArrayList *arrayList, int index, int count)
|
||||
* Removes all elements from the ArrayList.
|
||||
*/
|
||||
|
||||
void ArrayList_Clear(wArrayList *arrayList)
|
||||
void ArrayList_Clear(wArrayList* arrayList)
|
||||
{
|
||||
int index;
|
||||
|
||||
@ -205,7 +206,7 @@ void ArrayList_Clear(wArrayList *arrayList)
|
||||
* Determines whether an element is in the ArrayList.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_Contains(wArrayList *arrayList, void *obj)
|
||||
BOOL ArrayList_Contains(wArrayList* arrayList, void* obj)
|
||||
{
|
||||
int index;
|
||||
BOOL rc = FALSE;
|
||||
@ -231,7 +232,7 @@ BOOL ArrayList_Contains(wArrayList *arrayList, void *obj)
|
||||
* Adds an object to the end of the ArrayList.
|
||||
*/
|
||||
|
||||
int ArrayList_Add(wArrayList *arrayList, void *obj)
|
||||
int ArrayList_Add(wArrayList* arrayList, void* obj)
|
||||
{
|
||||
int index = -1;
|
||||
|
||||
@ -240,9 +241,9 @@ int ArrayList_Add(wArrayList *arrayList, void *obj)
|
||||
|
||||
if (arrayList->size + 1 > arrayList->capacity)
|
||||
{
|
||||
void **newArray;
|
||||
void** newArray;
|
||||
int newCapacity = arrayList->capacity * arrayList->growthFactor;
|
||||
newArray = (void **)realloc(arrayList->array, sizeof(void *) * newCapacity);
|
||||
newArray = (void**)realloc(arrayList->array, sizeof(void*) * newCapacity);
|
||||
|
||||
if (!newArray)
|
||||
goto out;
|
||||
@ -265,7 +266,7 @@ out:
|
||||
* Inserts an element into the ArrayList at the specified index.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_Insert(wArrayList *arrayList, int index, void *obj)
|
||||
BOOL ArrayList_Insert(wArrayList* arrayList, int index, void* obj)
|
||||
{
|
||||
BOOL ret = TRUE;
|
||||
|
||||
@ -294,7 +295,7 @@ BOOL ArrayList_Insert(wArrayList *arrayList, int index, void *obj)
|
||||
* Removes the first occurrence of a specific object from the ArrayList.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_Remove(wArrayList *arrayList, void *obj)
|
||||
BOOL ArrayList_Remove(wArrayList* arrayList, void* obj)
|
||||
{
|
||||
int index;
|
||||
BOOL found = FALSE;
|
||||
@ -330,7 +331,7 @@ BOOL ArrayList_Remove(wArrayList *arrayList, void *obj)
|
||||
* Removes the element at the specified index of the ArrayList.
|
||||
*/
|
||||
|
||||
BOOL ArrayList_RemoveAt(wArrayList *arrayList, int index)
|
||||
BOOL ArrayList_RemoveAt(wArrayList* arrayList, int index)
|
||||
{
|
||||
BOOL ret = TRUE;
|
||||
|
||||
@ -361,7 +362,7 @@ BOOL ArrayList_RemoveAt(wArrayList *arrayList, int index)
|
||||
* in the ArrayList that contains the specified number of elements and ends at the specified index.
|
||||
*/
|
||||
|
||||
int ArrayList_IndexOf(wArrayList *arrayList, void *obj, int startIndex, int count)
|
||||
int ArrayList_IndexOf(wArrayList* arrayList, void* obj, int startIndex, int count)
|
||||
{
|
||||
int index;
|
||||
BOOL found = FALSE;
|
||||
@ -403,7 +404,7 @@ int ArrayList_IndexOf(wArrayList *arrayList, void *obj, int startIndex, int coun
|
||||
* in the ArrayList that contains the specified number of elements and ends at the specified index.
|
||||
*/
|
||||
|
||||
int ArrayList_LastIndexOf(wArrayList *arrayList, void *obj, int startIndex, int count)
|
||||
int ArrayList_LastIndexOf(wArrayList* arrayList, void* obj, int startIndex, int count)
|
||||
{
|
||||
int index;
|
||||
BOOL found = FALSE;
|
||||
@ -435,7 +436,7 @@ int ArrayList_LastIndexOf(wArrayList *arrayList, void *obj, int startIndex, int
|
||||
return index;
|
||||
}
|
||||
|
||||
static BOOL ArrayList_DefaultCompare(void *objA, void *objB)
|
||||
static BOOL ArrayList_DefaultCompare(const void* objA, const void* objB)
|
||||
{
|
||||
return objA == objB ? TRUE : FALSE;
|
||||
}
|
||||
@ -444,10 +445,10 @@ static BOOL ArrayList_DefaultCompare(void *objA, void *objB)
|
||||
* Construction, Destruction
|
||||
*/
|
||||
|
||||
wArrayList *ArrayList_New(BOOL synchronized)
|
||||
wArrayList* ArrayList_New(BOOL synchronized)
|
||||
{
|
||||
wArrayList *arrayList = NULL;
|
||||
arrayList = (wArrayList *)calloc(1, sizeof(wArrayList));
|
||||
wArrayList* arrayList = NULL;
|
||||
arrayList = (wArrayList*)calloc(1, sizeof(wArrayList));
|
||||
|
||||
if (!arrayList)
|
||||
return NULL;
|
||||
@ -456,7 +457,7 @@ wArrayList *ArrayList_New(BOOL synchronized)
|
||||
arrayList->capacity = 32;
|
||||
arrayList->growthFactor = 2;
|
||||
arrayList->object.fnObjectEquals = ArrayList_DefaultCompare;
|
||||
arrayList->array = (void **)calloc(arrayList->capacity, sizeof(void *));
|
||||
arrayList->array = (void**)calloc(arrayList->capacity, sizeof(void*));
|
||||
|
||||
if (!arrayList->array)
|
||||
goto out_free;
|
||||
@ -468,7 +469,7 @@ out_free:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ArrayList_Free(wArrayList *arrayList)
|
||||
void ArrayList_Free(wArrayList* arrayList)
|
||||
{
|
||||
if (!arrayList)
|
||||
return;
|
||||
|
@ -320,7 +320,7 @@ BOOL LinkedList_Enumerator_MoveNext(wLinkedList* list)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL default_equal_function(void* objA, void* objB)
|
||||
static BOOL default_equal_function(const void* objA, const void* objB)
|
||||
{
|
||||
return objA == objB;
|
||||
}
|
||||
|
@ -155,7 +155,8 @@ int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
|
||||
|
||||
if (count)
|
||||
{
|
||||
pKeys = (ULONG_PTR *) calloc(count, sizeof(ULONG_PTR));
|
||||
pKeys = (ULONG_PTR*) calloc(count, sizeof(ULONG_PTR));
|
||||
|
||||
if (!pKeys)
|
||||
{
|
||||
if (listDictionary->synchronized)
|
||||
@ -190,7 +191,7 @@ int ListDictionary_GetKeys(wListDictionary* listDictionary, ULONG_PTR** ppKeys)
|
||||
* Adds an entry with the specified key and value into the ListDictionary.
|
||||
*/
|
||||
|
||||
BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
||||
BOOL ListDictionary_Add(wListDictionary* listDictionary, const void* key, void* value)
|
||||
{
|
||||
wListDictionaryItem* item;
|
||||
wListDictionaryItem* lastItem;
|
||||
@ -203,12 +204,12 @@ BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
item = (wListDictionaryItem*) malloc(sizeof(wListDictionaryItem));
|
||||
|
||||
if (!item)
|
||||
goto out_error;
|
||||
|
||||
item->key = key;
|
||||
item->key = (void*)key;
|
||||
item->value = value;
|
||||
|
||||
item->next = NULL;
|
||||
|
||||
if (!listDictionary->head)
|
||||
@ -227,6 +228,7 @@ BOOL ListDictionary_Add(wListDictionary* listDictionary, void* key, void* value)
|
||||
|
||||
ret = TRUE;
|
||||
out_error:
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
@ -277,7 +279,7 @@ void ListDictionary_Clear(wListDictionary* listDictionary)
|
||||
* Determines whether the ListDictionary contains a specific key.
|
||||
*/
|
||||
|
||||
BOOL ListDictionary_Contains(wListDictionary* listDictionary, void* key)
|
||||
BOOL ListDictionary_Contains(wListDictionary* listDictionary, const void* key)
|
||||
{
|
||||
wListDictionaryItem* item;
|
||||
OBJECT_EQUALS_FN keyEquals;
|
||||
@ -309,7 +311,7 @@ BOOL ListDictionary_Contains(wListDictionary* listDictionary, void* key)
|
||||
* Removes the entry with the specified key from the ListDictionary.
|
||||
*/
|
||||
|
||||
void* ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
||||
void* ListDictionary_Remove(wListDictionary* listDictionary, const void* key)
|
||||
{
|
||||
void* value = NULL;
|
||||
wListDictionaryItem* item;
|
||||
@ -323,7 +325,6 @@ void* ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
keyEquals = listDictionary->objectKey.fnObjectEquals;
|
||||
|
||||
item = listDictionary->head;
|
||||
prevItem = NULL;
|
||||
|
||||
@ -335,6 +336,7 @@ void* ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
||||
listDictionary->head = item->next;
|
||||
else
|
||||
prevItem->next = item->next;
|
||||
|
||||
value = item->value;
|
||||
free(item);
|
||||
break;
|
||||
@ -354,10 +356,10 @@ void* ListDictionary_Remove(wListDictionary* listDictionary, void* key)
|
||||
* Removes the first (head) entry from the list
|
||||
*/
|
||||
|
||||
void *ListDictionary_Remove_Head(wListDictionary* listDictionary)
|
||||
void* ListDictionary_Remove_Head(wListDictionary* listDictionary)
|
||||
{
|
||||
wListDictionaryItem* item;
|
||||
void *value = NULL;
|
||||
void* value = NULL;
|
||||
|
||||
if (!listDictionary)
|
||||
return NULL;
|
||||
@ -375,6 +377,7 @@ void *ListDictionary_Remove_Head(wListDictionary* listDictionary)
|
||||
|
||||
if (listDictionary->synchronized)
|
||||
LeaveCriticalSection(&listDictionary->lock);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -382,7 +385,7 @@ void *ListDictionary_Remove_Head(wListDictionary* listDictionary)
|
||||
* Get an item value using key
|
||||
*/
|
||||
|
||||
void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key)
|
||||
void* ListDictionary_GetItemValue(wListDictionary* listDictionary, const void* key)
|
||||
{
|
||||
void* value = NULL;
|
||||
wListDictionaryItem* item = NULL;
|
||||
@ -421,7 +424,7 @@ void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key)
|
||||
* Set an item value using key
|
||||
*/
|
||||
|
||||
BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, void* value)
|
||||
BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, const void* key, void* value)
|
||||
{
|
||||
BOOL status = FALSE;
|
||||
wListDictionaryItem* item;
|
||||
@ -434,6 +437,7 @@ BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, voi
|
||||
EnterCriticalSection(&listDictionary->lock);
|
||||
|
||||
keyEquals = listDictionary->objectKey.fnObjectEquals;
|
||||
|
||||
if (listDictionary->head)
|
||||
{
|
||||
item = listDictionary->head;
|
||||
@ -450,6 +454,7 @@ BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, voi
|
||||
{
|
||||
if (listDictionary->objectValue.fnObjectFree)
|
||||
listDictionary->objectValue.fnObjectFree(item->value);
|
||||
|
||||
item->value = value;
|
||||
}
|
||||
|
||||
@ -462,7 +467,7 @@ BOOL ListDictionary_SetItemValue(wListDictionary* listDictionary, void* key, voi
|
||||
return status;
|
||||
}
|
||||
|
||||
static BOOL default_equal_function(void *obj1, void *obj2)
|
||||
static BOOL default_equal_function(const void* obj1, const void* obj2)
|
||||
{
|
||||
return (obj1 == obj2);
|
||||
}
|
||||
@ -473,7 +478,6 @@ static BOOL default_equal_function(void *obj1, void *obj2)
|
||||
wListDictionary* ListDictionary_New(BOOL synchronized)
|
||||
{
|
||||
wListDictionary* listDictionary = NULL;
|
||||
|
||||
listDictionary = (wListDictionary*) calloc(1, sizeof(wListDictionary));
|
||||
|
||||
if (!listDictionary)
|
||||
@ -489,7 +493,6 @@ wListDictionary* ListDictionary_New(BOOL synchronized)
|
||||
|
||||
listDictionary->objectKey.fnObjectEquals = default_equal_function;
|
||||
listDictionary->objectValue.fnObjectEquals = default_equal_function;
|
||||
|
||||
return listDictionary;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
int Queue_Count(wQueue* queue)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (queue->synchronized)
|
||||
EnterCriticalSection(&queue->lock);
|
||||
|
||||
@ -48,6 +49,7 @@ int Queue_Count(wQueue* queue)
|
||||
|
||||
if (queue->synchronized)
|
||||
LeaveCriticalSection(&queue->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -150,12 +152,11 @@ BOOL Queue_Enqueue(wQueue* queue, void* obj)
|
||||
{
|
||||
int old_capacity;
|
||||
int new_capacity;
|
||||
void **newArray;
|
||||
|
||||
void** newArray;
|
||||
old_capacity = queue->capacity;
|
||||
new_capacity = queue->capacity * queue->growthFactor;
|
||||
newArray = (void**)realloc(queue->array, sizeof(void*) * new_capacity);
|
||||
|
||||
newArray = (void **)realloc(queue->array, sizeof(void*) * new_capacity);
|
||||
if (!newArray)
|
||||
{
|
||||
ret = FALSE;
|
||||
@ -177,12 +178,12 @@ BOOL Queue_Enqueue(wQueue* queue, void* obj)
|
||||
queue->array[queue->tail] = obj;
|
||||
queue->tail = (queue->tail + 1) % queue->capacity;
|
||||
queue->size++;
|
||||
|
||||
SetEvent(queue->event);
|
||||
|
||||
out:
|
||||
|
||||
if (queue->synchronized)
|
||||
LeaveCriticalSection(&queue->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -234,7 +235,7 @@ void* Queue_Peek(wQueue* queue)
|
||||
return obj;
|
||||
}
|
||||
|
||||
static BOOL default_queue_equals(void *obj1, void *obj2)
|
||||
static BOOL default_queue_equals(const void* obj1, const void* obj2)
|
||||
{
|
||||
return (obj1 == obj2);
|
||||
}
|
||||
@ -246,14 +247,13 @@ static BOOL default_queue_equals(void *obj1, void *obj2)
|
||||
wQueue* Queue_New(BOOL synchronized, int capacity, int growthFactor)
|
||||
{
|
||||
wQueue* queue = NULL;
|
||||
queue = (wQueue*)calloc(1, sizeof(wQueue));
|
||||
|
||||
queue = (wQueue *)calloc(1, sizeof(wQueue));
|
||||
if (!queue)
|
||||
return NULL;
|
||||
|
||||
queue->capacity = 32;
|
||||
queue->growthFactor = 2;
|
||||
|
||||
queue->synchronized = synchronized;
|
||||
|
||||
if (capacity > 0)
|
||||
@ -262,11 +262,13 @@ wQueue* Queue_New(BOOL synchronized, int capacity, int growthFactor)
|
||||
if (growthFactor > 0)
|
||||
queue->growthFactor = growthFactor;
|
||||
|
||||
queue->array = (void **)calloc(queue->capacity, sizeof(void *));
|
||||
queue->array = (void**)calloc(queue->capacity, sizeof(void*));
|
||||
|
||||
if (!queue->array)
|
||||
goto out_free;
|
||||
|
||||
queue->event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
if (!queue->event)
|
||||
goto out_free_array;
|
||||
|
||||
@ -275,7 +277,6 @@ wQueue* Queue_New(BOOL synchronized, int capacity, int growthFactor)
|
||||
|
||||
queue->object.fnObjectEquals = default_queue_equals;
|
||||
return queue;
|
||||
|
||||
out_free_event:
|
||||
CloseHandle(queue->event);
|
||||
out_free_array:
|
||||
@ -291,7 +292,6 @@ void Queue_Free(wQueue* queue)
|
||||
return;
|
||||
|
||||
Queue_Clear(queue);
|
||||
|
||||
CloseHandle(queue->event);
|
||||
DeleteCriticalSection(&queue->lock);
|
||||
free(queue->array);
|
||||
|
@ -128,12 +128,13 @@ void Stack_Push(wStack* stack, void* obj)
|
||||
if ((stack->size + 1) >= stack->capacity)
|
||||
{
|
||||
int new_cap;
|
||||
void **new_arr;
|
||||
|
||||
void** new_arr;
|
||||
new_cap = stack->capacity * 2;
|
||||
new_arr = (void**) realloc(stack->array, sizeof(void*) * new_cap);
|
||||
|
||||
if (!new_arr)
|
||||
return;
|
||||
|
||||
stack->array = new_arr;
|
||||
stack->capacity = new_cap;
|
||||
}
|
||||
@ -185,7 +186,7 @@ void* Stack_Peek(wStack* stack)
|
||||
}
|
||||
|
||||
|
||||
static BOOL default_stack_equals(void *obj1, void *obj2)
|
||||
static BOOL default_stack_equals(const void* obj1, const void* obj2)
|
||||
{
|
||||
return (obj1 == obj2);
|
||||
}
|
||||
@ -197,24 +198,23 @@ static BOOL default_stack_equals(void *obj1, void *obj2)
|
||||
wStack* Stack_New(BOOL synchronized)
|
||||
{
|
||||
wStack* stack = NULL;
|
||||
stack = (wStack*)calloc(1, sizeof(wStack));
|
||||
|
||||
stack = (wStack *)calloc(1, sizeof(wStack));
|
||||
if (!stack)
|
||||
return NULL;
|
||||
|
||||
stack->object.fnObjectEquals = default_stack_equals;
|
||||
stack->synchronized = synchronized;
|
||||
|
||||
stack->capacity = 32;
|
||||
stack->array = (void**) calloc(stack->capacity, sizeof(void*));
|
||||
|
||||
if (!stack->array)
|
||||
goto out_free;
|
||||
|
||||
if (stack->synchronized && !InitializeCriticalSectionAndSpinCount(&stack->lock, 4000))
|
||||
goto out_free_array;
|
||||
goto out_free_array;
|
||||
|
||||
return stack;
|
||||
|
||||
out_free_array:
|
||||
free(stack->array);
|
||||
out_free:
|
||||
@ -230,7 +230,6 @@ void Stack_Free(wStack* stack)
|
||||
DeleteCriticalSection(&stack->lock);
|
||||
|
||||
free(stack->array);
|
||||
|
||||
free(stack);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user