From a9c6b8ba7212e31893ea3f589e868c2b891c871b Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Mon, 15 Dec 2025 20:06:34 +0000 Subject: [PATCH] Fix MSVC Spectre warnings --- src/primitives/strings/str8/str8.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/primitives/strings/str8/str8.c b/src/primitives/strings/str8/str8.c index 79f7e46..7dfc2f0 100644 --- a/src/primitives/strings/str8/str8.c +++ b/src/primitives/strings/str8/str8.c @@ -246,8 +246,15 @@ void wapp_str8_to_lower(Str8 *dst, Str8RO *src) { wapp_debug_assert(dst->capacity >= src->capacity, "`dst` does not have enough capacity"); dst->size = src->size; - for (u64 i = 0; i < src->size; ++i) { - wapp_str8_set(dst, i, (u8)tolower(wapp_str8_get(src, i))); + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 index = 0; + b8 running = true; + while (running) { + wapp_str8_set(dst, index, (u8)tolower(wapp_str8_get(src, index))); + ++index; + running = index < src->size; } } @@ -256,8 +263,15 @@ void wapp_str8_to_upper(Str8 *dst, Str8RO *src) { wapp_debug_assert(dst->capacity >= src->capacity, "`dst` does not have enough capacity"); dst->size = src->size; - for (u64 i = 0; i < src->size; ++i) { - wapp_str8_set(dst, i, (u8)toupper(wapp_str8_get(src, i))); + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 index = 0; + b8 running = true; + while (running) { + wapp_str8_set(dst, index, (u8)toupper(wapp_str8_get(src, index))); + ++index; + running = index < src->size; } }