From a5b2a4fab98c0b88367c45ebee62cbe8015a9cbf Mon Sep 17 00:00:00 2001 From: Gittensor Miner Date: Fri, 23 Jan 2026 13:31:24 +0200 Subject: [PATCH] Fix: Add exception handling to setValue functions Replace TODO comments with proper exception handling in ArchMiscWindows::setValue methods. When a nullptr registry key is passed, the functions now throw std::invalid_argument instead of silently returning, improving error handling and making bugs easier to detect. Removed assert statements as they are redundant with the exception handling. This addresses the TODO comments in lines 163 and 173. --- src/lib/arch/win32/ArchMiscWindows.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/arch/win32/ArchMiscWindows.cpp b/src/lib/arch/win32/ArchMiscWindows.cpp index b202b15aa..4f2cfc11d 100644 --- a/src/lib/arch/win32/ArchMiscWindows.cpp +++ b/src/lib/arch/win32/ArchMiscWindows.cpp @@ -17,6 +17,7 @@ #include #include +#include // Useful for debugging Windows specific bootstrapping code before the logging system is initialized. // This output can be viewed by attaching a Microsoft debugger or by using the DebugView program. @@ -158,20 +159,16 @@ ArchMiscWindows::EValueType ArchMiscWindows::typeOfValue(HKEY key, const TCHAR * void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, const std::string &value) { - assert(key != nullptr); if (key == nullptr) { - // TODO: throw exception - return; + throw std::invalid_argument("Registry key cannot be nullptr"); } RegSetValueEx(key, name, 0, REG_SZ, reinterpret_cast(value.c_str()), (DWORD)value.size() + 1); } void ArchMiscWindows::setValue(HKEY key, const TCHAR *name, DWORD value) { - assert(key != nullptr); if (key == nullptr) { - // TODO: throw exception - return; + throw std::invalid_argument("Registry key cannot be nullptr"); } RegSetValueEx(key, name, 0, REG_DWORD, reinterpret_cast(&value), sizeof(DWORD)); }