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,16 +29,20 @@ 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;
} }
if (dst->size > 0) { if (dst->size > 0) {
char dst_last = wapp_str8_get(dst, dst->size - 1); char dst_last = wapp_str8_get(dst, dst->size - 1);
char node_start = wapp_str8_get(node->string, 0); char node_start = wapp_str8_get(node->string, 0);
bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP; bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP;
if (add_path_sep) { if (add_path_sep) {
@ -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;