Address Windows Spectre mitigation warnings

This commit is contained in:
2025-02-16 14:55:17 +00:00
parent ca2b1cbf23
commit 19134d0e15
2 changed files with 104 additions and 33 deletions

View File

@@ -156,11 +156,18 @@ i64 wapp_str8_find(Str8RO *str, Str8RO substr) {
return -1;
}
for (u64 i = 0; i < str->size; ++i) {
const c8 *sub = str->buf + i;
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
u64 char_index = 0;
bool running = true;
while (running) {
const c8 *sub = str->buf + char_index;
if (memcmp(sub, substr.buf, substr.size) == 0) {
return i;
return char_index;
}
++char_index;
running = char_index < str->size;
}
return -1;
@@ -171,11 +178,18 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
return -1;
}
for (i64 i = str->size - substr.size; i >= 0; --i) {
const c8 *sub = str->buf + i;
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
i64 char_index = str->size - substr.size;
bool running = true;
while (running) {
const c8 *sub = str->buf + char_index;
if (memcmp(sub, substr.buf, substr.size) == 0) {
return i;
return char_index;
}
--char_index;
running = char_index >= 0;
}
return -1;
@@ -303,13 +317,20 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
u64 capacity = list->total_size + (delimiter->size * (list->node_count - 1));
Str8 *output = wapp_str8_buf_alloc(allocator, capacity);
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
Str8Node *node;
for (u64 i = 0; i < list->node_count; ++i) {
node = wapp_str8_list_get(list, i);
u64 node_index = 0;
bool running = true;
while (running) {
node = wapp_str8_list_get(list, node_index);
wapp_str8_concat_capped(output, node->string);
if (i + 1 < list->node_count) {
if (node_index + 1 < list->node_count) {
wapp_str8_concat_capped(output, delimiter);
}
++node_index;
running = node_index < list->node_count;
}
return output;