From b476ceaeef86c66419465cb807a713bfb324018a Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Sun, 20 Apr 2025 20:28:02 +0100 Subject: [PATCH] Fix MSVC Spectre warnings --- src/core/strings/str8/str8.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/core/strings/str8/str8.c b/src/core/strings/str8/str8.c index fb6900b..7304c62 100644 --- a/src/core/strings/str8/str8.c +++ b/src/core/strings/str8/str8.c @@ -422,8 +422,16 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d bool running = true; while (running) { node = wapp_str8_list_get(list, node_index); + if (!node) { + break; + } + wapp_str8_concat_capped(output, node->item); - if (node_index + 1 < list->node_count) { + + // NOTE (Abdelrahman): Comparison extracted to variable to silence + // MSVC Spectre mitigation warnings + bool not_last = node_index + 1 < list->node_count; + if (not_last) { wapp_str8_concat_capped(output, delimiter); } @@ -439,10 +447,21 @@ u64 wapp_str8_list_total_size(const Str8List *list) { return 0; } - u64 output = 0; - for (u64 i = 0; i < list->node_count; ++i) { - Str8Node *node = wapp_str8_list_get(list, i); - output += node->item->size; + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + Str8Node* node; + u64 node_index = 0; + u64 output = 0; + bool running = true; + while (running) { + node = wapp_str8_list_get(list, node_index); + if (!node) { + break; + } + + output += node->item->size; + ++node_index; + running = node_index < list->node_count; } return output;