From 81b9638eaaf004055be336df858f60e584124256 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 2 Aug 2021 00:33:34 -0700 Subject: [PATCH] Fix segfault when comparing mods --- src/pc/network/packets/packet_join.c | 4 ++-- src/pc/utils/string_linked_list.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pc/network/packets/packet_join.c b/src/pc/network/packets/packet_join.c index 6db81996..31aee61f 100644 --- a/src/pc/network/packets/packet_join.c +++ b/src/pc/network/packets/packet_join.c @@ -151,7 +151,7 @@ void network_receive_join(struct Packet* p) { string_builder_append(builder, "\\#c8c8c8\\Yours: "); struct StringLinkedList* node = &gRegisteredMods; bool first = true; - while (node != NULL) { + while (node != NULL && node->string != NULL) { string_builder_append(builder, first ? "\\#%s\\%s" : ", \\#%s\\%s", string_linked_list_contains(&head, node->string) ? "a0ffa0" : "ffa0a0" , node->string); @@ -162,7 +162,7 @@ void network_receive_join(struct Packet* p) { string_builder_append(builder, "\n\n\\#c8c8c8\\Theirs: "); node = &head; first = true; - while (node != NULL) { + while (node != NULL && node->string != NULL) { string_builder_append(builder, first ? "\\#%s\\%s" : ", \\#%s\\%s", string_linked_list_contains(&gRegisteredMods, node->string) ? "a0ffa0" : "ffa0a0" , node->string); diff --git a/src/pc/utils/string_linked_list.c b/src/pc/utils/string_linked_list.c index ef795aea..b81dcf59 100644 --- a/src/pc/utils/string_linked_list.c +++ b/src/pc/utils/string_linked_list.c @@ -21,6 +21,9 @@ void string_linked_list_append(struct StringLinkedList* node, char* string) { } bool string_linked_list_contains(struct StringLinkedList* node, char* string) { + if (string == NULL) { + return false; + } int length1 = strlen(string); while (node != NULL && node->string != NULL) { int length2 = strlen(node->string);