From 00c5a42eef69b4f593aa8e3bb4ead6061ea5ea1b Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 28 Jul 2021 16:20:32 +0200 Subject: [PATCH] Fixed warnings in TestLinkedList --- winpr/libwinpr/utils/test/TestLinkedList.c | 64 ++++++++++++++-------- winpr/libwinpr/utils/test/TestQueue.c | 15 +++-- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/winpr/libwinpr/utils/test/TestLinkedList.c b/winpr/libwinpr/utils/test/TestLinkedList.c index 9848bfcb7..56b96782f 100644 --- a/winpr/libwinpr/utils/test/TestLinkedList.c +++ b/winpr/libwinpr/utils/test/TestLinkedList.c @@ -7,10 +7,19 @@ int TestLinkedList(int argc, char* argv[]) { int count; wLinkedList* list; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + list = LinkedList_New(); - LinkedList_AddFirst(list, (void*)(size_t)1); - LinkedList_AddLast(list, (void*)(size_t)2); - LinkedList_AddLast(list, (void*)(size_t)3); + if (!list) + return -1; + + if (!LinkedList_AddFirst(list, (void*)(size_t)1)) + return -1; + if (!LinkedList_AddLast(list, (void*)(size_t)2)) + return -1; + if (!LinkedList_AddLast(list, (void*)(size_t)3)) + return -1; count = LinkedList_Count(list); if (count != 3) @@ -23,12 +32,11 @@ int TestLinkedList(int argc, char* argv[]) while (LinkedList_Enumerator_MoveNext(list)) { - printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list)); + printf("\t%p\n", LinkedList_Enumerator_Current(list)); } printf("\n"); - printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list), - (size_t)LinkedList_Last(list)); + printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), LinkedList_Last(list)); LinkedList_RemoveFirst(list); LinkedList_RemoveLast(list); count = LinkedList_Count(list); @@ -43,12 +51,11 @@ int TestLinkedList(int argc, char* argv[]) while (LinkedList_Enumerator_MoveNext(list)) { - printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list)); + printf("\t%p\n", LinkedList_Enumerator_Current(list)); } printf("\n"); - printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list), - (size_t)LinkedList_Last(list)); + printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), LinkedList_Last(list)); LinkedList_RemoveFirst(list); LinkedList_RemoveLast(list); count = LinkedList_Count(list); @@ -59,9 +66,12 @@ int TestLinkedList(int argc, char* argv[]) return -1; } - LinkedList_AddFirst(list, (void*)(size_t)4); - LinkedList_AddLast(list, (void*)(size_t)5); - LinkedList_AddLast(list, (void*)(size_t)6); + if (!LinkedList_AddFirst(list, (void*)(size_t)4)) + return -1; + if (!LinkedList_AddLast(list, (void*)(size_t)5)) + return -1; + if (!LinkedList_AddLast(list, (void*)(size_t)6)) + return -1; count = LinkedList_Count(list); if (count != 3) @@ -74,45 +84,51 @@ int TestLinkedList(int argc, char* argv[]) while (LinkedList_Enumerator_MoveNext(list)) { - printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list)); + printf("\t%p\n", LinkedList_Enumerator_Current(list)); } printf("\n"); - printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list), - (size_t)LinkedList_Last(list)); - LinkedList_Remove(list, (void*)(size_t)5); + printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), LinkedList_Last(list)); + if (!LinkedList_Remove(list, (void*)(size_t)5)) + return -1; LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { - printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list)); + printf("\t%p\n", LinkedList_Enumerator_Current(list)); } printf("\n"); - printf("LinkedList First: %" PRIuz " Last: %" PRIuz "\n", (size_t)LinkedList_First(list), - (size_t)LinkedList_Last(list)); + printf("LinkedList First: %p Last: %p\n", LinkedList_First(list), LinkedList_Last(list)); LinkedList_Free(list); /* Test enumerator robustness */ /* enumerator on an empty list */ list = LinkedList_New(); + if (!list) + return -1; LinkedList_Enumerator_Reset(list); while (LinkedList_Enumerator_MoveNext(list)) { - printf("\terror: %" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list)); + printf("\terror: %p\n", LinkedList_Enumerator_Current(list)); } printf("\n"); LinkedList_Free(list); /* Use an enumerator without reset */ list = LinkedList_New(); - LinkedList_AddFirst(list, (void*)(size_t)4); - LinkedList_AddLast(list, (void*)(size_t)5); - LinkedList_AddLast(list, (void*)(size_t)6); + if (!list) + return -1; + if (!LinkedList_AddFirst(list, (void*)(size_t)4)) + return -1; + if (!LinkedList_AddLast(list, (void*)(size_t)5)) + return -1; + if (!LinkedList_AddLast(list, (void*)(size_t)6)) + return -1; while (LinkedList_Enumerator_MoveNext(list)) { - printf("\t%" PRIuz "\n", (size_t)LinkedList_Enumerator_Current(list)); + printf("\t%p\n", LinkedList_Enumerator_Current(list)); } printf("\n"); diff --git a/winpr/libwinpr/utils/test/TestQueue.c b/winpr/libwinpr/utils/test/TestQueue.c index c0f9a2012..bcb288423 100644 --- a/winpr/libwinpr/utils/test/TestQueue.c +++ b/winpr/libwinpr/utils/test/TestQueue.c @@ -5,11 +5,14 @@ int TestQueue(int argc, char* argv[]) { - int item; - int index; - int count; + size_t item; + size_t index; + size_t count; wQueue* queue; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + queue = Queue_New(TRUE, -1, -1); if (!queue) return -1; @@ -20,18 +23,18 @@ int TestQueue(int argc, char* argv[]) } count = Queue_Count(queue); - printf("queue count: %d\n", count); + printf("queue count: %" PRIuz "\n", count); for (index = 1; index <= 10; index++) { - item = (int)(size_t)Queue_Dequeue(queue); + item = (size_t)Queue_Dequeue(queue); if (item != index) return -1; } count = Queue_Count(queue); - printf("queue count: %d\n", count); + printf("queue count: %" PRIuz "\n", count); Queue_Enqueue(queue, (void*)(size_t)1); Queue_Enqueue(queue, (void*)(size_t)2);