From c2bef2bfa9acd022d0e792577be526f08793c4bb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 9 Jun 2021 12:31:10 +0200 Subject: [PATCH] Fixed return value checks for ArrayList_Append and HashTable_Insert --- channels/geometry/client/geometry_main.c | 4 ++-- channels/tsmf/client/tsmf_media.c | 4 ++-- client/X11/xf_cliprdr.c | 24 ++++++++---------------- libfreerdp/codec/progressive.c | 2 +- libfreerdp/core/server.c | 2 +- winpr/libwinpr/wnd/wnd.c | 4 +++- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/channels/geometry/client/geometry_main.c b/channels/geometry/client/geometry_main.c index 818d5cdff..8abf8fb74 100644 --- a/channels/geometry/client/geometry_main.c +++ b/channels/geometry/client/geometry_main.c @@ -246,8 +246,8 @@ static UINT geometry_recv_pdu(GEOMETRY_CHANNEL_CALLBACK* callback, wStream* s) mappedGeometry->refCounter = 1; mappedGeometry->mappingId = id; - if (HashTable_Insert(context->geometries, &(mappedGeometry->mappingId), - mappedGeometry) < 0) + if (!HashTable_Insert(context->geometries, &(mappedGeometry->mappingId), + mappedGeometry)) { WLog_ERR(TAG, "unable to register geometry 0x%" PRIx64 " in the table", id); free(mappedGeometry); diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index 119de0a62..d7c587323 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -373,7 +373,7 @@ TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, goto error_add; obj->fnObjectFree = _tsmf_stream_free; - if (ArrayList_Append(presentation_list, presentation) < 0) + if (!ArrayList_Append(presentation_list, presentation)) goto error_add; return presentation; @@ -1279,7 +1279,7 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, if (!stream->ack_thread) goto error_ack_thread; - if (ArrayList_Append(presentation->stream_list, stream) < 0) + if (!ArrayList_Append(presentation->stream_list, stream)) goto error_add; stream->rdpcontext = rdpcontext; diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index c2097cc72..40bd33d38 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -1782,16 +1782,8 @@ static BOOL xf_cliprdr_fuse_create_nodes(xfClipboard* clipboard, wStream* s, siz WLog_ERR(TAG, "fail to alloc hashtable"); return FALSE; } - if (!HashTable_SetHashFunction(mapDir, HashTable_StringHash)) + if (!HashTable_SetupForStringData(mapDir, FALSE)) goto error; - { - wObject* obj = HashTable_KeyObject(mapDir); - if (!obj) - goto error; - obj->fnObjectNew = HashTable_StringClone; - obj->fnObjectFree = HashTable_StringFree; - obj->fnObjectEquals = HashTable_StringCompare; - } FILEDESCRIPTORW* descriptor = (FILEDESCRIPTORW*)calloc(1, sizeof(FILEDESCRIPTORW)); if (!descriptor) @@ -1831,7 +1823,7 @@ static BOOL xf_cliprdr_fuse_create_nodes(xfClipboard* clipboard, wStream* s, siz break; inode->parent_ino = 1; inode->name = baseName; - if (ArrayList_Append(rootNode->child_inos, (void*)inode->ino) < 0) + if (!ArrayList_Append(rootNode->child_inos, (void*)inode->ino)) break; } else @@ -1850,7 +1842,7 @@ static BOOL xf_cliprdr_fuse_create_nodes(xfClipboard* clipboard, wStream* s, siz break; inode->parent_ino = parent->ino; inode->name = baseName; - if (ArrayList_Append(parent->child_inos, (void*)inode->ino) < 0) + if (!ArrayList_Append(parent->child_inos, (void*)inode->ino)) break; free(dirName); dirName = NULL; @@ -1908,7 +1900,7 @@ static BOOL xf_cliprdr_fuse_create_nodes(xfClipboard* clipboard, wStream* s, siz inode->st_mtim.tv_nsec = 0; } - if (ArrayList_Append(clipboard->ino_list, inode) < 0) + if (!ArrayList_Append(clipboard->ino_list, inode)) break; } /* clean up incomplete ino_list*/ @@ -1960,7 +1952,7 @@ static BOOL xf_cliprdr_fuse_generate_list(xfClipboard* clipboard, const BYTE* da ArrayList_Lock(clipboard->ino_list); xfCliprdrFuseInode* rootNode = xf_cliprdr_fuse_create_root_node(); - if (!rootNode || ArrayList_Append(clipboard->ino_list, rootNode) < 0) + if (!rootNode || !ArrayList_Append(clipboard->ino_list, rootNode)) { xf_cliprdr_fuse_inode_free(rootNode); WLog_ERR(TAG, "fail to alloc rootNode to ino_list"); @@ -2386,7 +2378,7 @@ static int xf_cliprdr_fuse_util_add_stream_list(xfClipboard* clipboard, fuse_req *stream_id = stream->stream_id; stream->req_ino = 0; clipboard->current_stream_id++; - if (ArrayList_Append(clipboard->stream_list, stream) < 0) + if (!ArrayList_Append(clipboard->stream_list, stream)) { err = ENOMEM; goto error; @@ -2607,7 +2599,7 @@ static void xf_cliprdr_fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char return; } - int res; + BOOL res; UINT32 stream_id; BOOL size_set = child_node->size_set; size_t lindex = child_node->lindex; @@ -2634,7 +2626,7 @@ static void xf_cliprdr_fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char clipboard->current_stream_id++; res = ArrayList_Append(clipboard->stream_list, stream); ArrayList_Unlock(clipboard->stream_list); - if (res < 0) + if (!res) { fuse_reply_err(req, ENOMEM); return; diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index 61e0fac37..ea1c3e9b2 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -357,7 +357,7 @@ static INLINE BOOL progressive_set_surface_data(PROGRESSIVE_CONTEXT* progressive key = ((ULONG_PTR)surfaceId) + 1; if (pData) - return HashTable_Insert(progressive->SurfaceContexts, (void*)key, pData) >= 0; + return HashTable_Insert(progressive->SurfaceContexts, (void*)key, pData); HashTable_Remove(progressive->SurfaceContexts, (void*)key); return TRUE; diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index eaf9e7766..787a128cc 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -828,7 +828,7 @@ HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName) goto error_free; } - if (HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm) < 0) + if (!HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm)) goto error_free; queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message; diff --git a/winpr/libwinpr/wnd/wnd.c b/winpr/libwinpr/wnd/wnd.c index a2894ac23..b01b0e6c0 100644 --- a/winpr/libwinpr/wnd/wnd.c +++ b/winpr/libwinpr/wnd/wnd.c @@ -191,7 +191,9 @@ ATOM WINAPI RegisterClassExA(CONST WNDCLASSEXA* lpwcx) _lpwcx = CloneWindowClass(lpwcx); - return ArrayList_Append(g_WindowClasses, (void*)_lpwcx); + if (!ArrayList_Append(g_WindowClasses, (void*)_lpwcx)) + return 0; + return ArrayList_Count(g_WindowClasses) - 1; } ATOM WINAPI RegisterClassExW(CONST WNDCLASSEXW* lpwcx)