Add set_value_multistring_nothrow for REG_MULTI_SZ writes#631
Add set_value_multistring_nothrow for REG_MULTI_SZ writes#631benhillis wants to merge 3 commits intomicrosoft:masterfrom
Conversation
Adds set_value_multistring_nothrow() - the missing nothrow counterpart to the existing set_value_multistring(). Two overloads matching the existing pattern. Uses try/CATCH_RETURN() since get_multistring_from_wstrings allocates internally. Gated behind WIL_USE_STL. Fixes microsoft#479
8390244 to
98ac5fc
Compare
|
It feels very weird and unnatural to have a "nothrow" function use exceptions internally -- I'm not aware of any existing place where this is done either. Coupled with the fact that the argument is I get why you are doing it, though. OOM and system errors are two very different classes of errors, and it's nice to have control flow that deals with error codes as opposed to exceptions, so I don't necessarily object to the idea. Curious what other folks think. |
I agree, and that's not the way things are typically done in wil, let me think about this a bit more. |
Replace try/CATCH_RETURN() with a truly nothrow implementation that builds the multi-sz buffer using HeapAlloc + memcpy, matching the idiomatic wil pattern for nothrow functions. - Pre-calculate total buffer size with overflow checks - Guard against size_t-to-DWORD truncation before calling RegSetKeyValueW - Use HeapAlloc for the temporary buffer (no COM dependency needed) - Relax preprocessor guard from WIL_USE_STL+WIL_ENABLE_EXCEPTIONS to just WIL_USE_STL since exceptions are no longer used internally Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…, add WI_ASSERT - Use unique_process_heap_ptr instead of raw HeapAlloc/HeapFree - Simplify memcpy to copy null terminator with c_str() (size + 1) - Add WI_ASSERT to verify offset matches expected buffer size Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds
set_value_multistring_nothrow()— the missing nothrow counterpart to the existingset_value_multistring().Two overloads, matching the existing pattern:
Uses
try/CATCH_RETURN()sinceget_multistring_from_wstringsallocates internally. Gated behindWIL_USE_STL.Tests cover round-trips via both overloads, empty arrays, default value names,
E_ACCESSDENIEDon read-only keys, and cross-verification with the cotaskmem nothrow reader.Fixes #479