Fix spectre warning for MSVC

This commit is contained in:
Abdelrahman Said 2025-02-22 18:04:05 +00:00
parent ed4ec54c7a
commit fe2bb65b06

View File

@ -29,8 +29,12 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
const Str8Node *first_node = wapp_str8_list_get(parts, 0); const Str8Node *first_node = wapp_str8_list_get(parts, 0);
wapp_str8_copy_str8_capped(dst, first_node->string); wapp_str8_copy_str8_capped(dst, first_node->string);
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
const Str8Node *node = first_node; const Str8Node *node = first_node;
for (u64 i = 1; i < parts->node_count; ++i) { u64 node_index = 1;
bool running = true;
while (running && node->next) {
node = node->next; node = node->next;
if (node->string->size == 0) { if (node->string->size == 0) {
continue; continue;
@ -47,6 +51,9 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
} }
wapp_str8_concat_capped(dst, node->string); wapp_str8_concat_capped(dst, node->string);
++node_index;
running = node_index < parts->node_count;
} }
return CPATH_JOIN_SUCCESS; return CPATH_JOIN_SUCCESS;