Fix Spectre warnings for MSVC

This commit is contained in:
Abdelrahman Said 2024-10-06 19:54:13 +01:00
parent 8d8fcf9dc5
commit ce656a6275

View File

@ -1,6 +1,7 @@
#include "cpath.h" #include "cpath.h"
#include "aliases.h" #include "aliases.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -47,7 +48,10 @@ void dirup(char *dst, u64 levels, const char *path) {
char tmp[256]; char tmp[256];
sprintf(tmp, "%c", PATH_SEP); sprintf(tmp, "%c", PATH_SEP);
if (sep_count < levels && strncmp(path, tmp, copy_count) != 0) { // NOTE (Abdelrahman): Conditions stored in variables to silence MSVC warning C5045
bool insufficient_levels = sep_count < levels;
bool path_to_copy_is_separator = strncmp(path, tmp, copy_count) != 0;
if (insufficient_levels && path_to_copy_is_separator) {
copy_count = 0; copy_count = 0;
} }