Silence the last two C4996 warnings in our code

hook_registry.cpp still used strncpy for the hook-name copy (the same
class the log-ring fix addressed) -- replace with a bounded memcpy.
coop_vk_layer.cpp's debug logger used _wfopen -- switch to _wfopen_s.
Both were the only remaining C4996s in our own code.
This commit is contained in:
2026-07-12 12:04:28 +02:00
parent ce996763d5
commit b2b8abdc51
2 changed files with 6 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
#include "hook_registry.hpp" #include "hook_registry.hpp"
#include <algorithm>
#include <atomic> #include <atomic>
#include <cstring> #include <cstring>
#include <mutex> #include <mutex>
@@ -35,8 +36,9 @@ int hook_register(const char* name, std::uint32_t subsystem)
return -1; // table full return -1; // table full
} }
Slot& s = g_slots[count]; Slot& s = g_slots[count];
std::strncpy(s.name, name, sizeof(s.name) - 1); const std::size_t len = std::min(std::strlen(name), sizeof(s.name) - 1);
s.name[sizeof(s.name) - 1] = '\0'; std::memcpy(s.name, name, len);
s.name[len] = '\0';
s.subsystem.store(subsystem, std::memory_order_relaxed); s.subsystem.store(subsystem, std::memory_order_relaxed);
s.installed.store(0, std::memory_order_relaxed); s.installed.store(0, std::memory_order_relaxed);
s.calls.store(0, std::memory_order_relaxed); s.calls.store(0, std::memory_order_relaxed);

View File

@@ -151,8 +151,8 @@ void logvk(const char* fmt, ...)
if (GetTempPathW(MAX_PATH, dir) == 0) { if (GetTempPathW(MAX_PATH, dir) == 0) {
return; return;
} }
FILE* f = _wfopen((std::wstring(dir) + L"coop_vk_layer.log").c_str(), L"a"); FILE* f = nullptr;
if (f == nullptr) { if (_wfopen_s(&f, (std::wstring(dir) + L"coop_vk_layer.log").c_str(), L"a") != 0 || f == nullptr) {
return; return;
} }
va_list ap; va_list ap;