Add set_value_multistring_nothrow for REG_MULTI_SZ writes#631
Conversation
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. |
aa93024 to
da4b4db
Compare
| if (data.empty()) | ||
| { | ||
| // An empty multi-string still requires a leading null plus the final terminator. | ||
| total_size_bytes = 2 * sizeof(wchar_t); | ||
| } |
There was a problem hiding this comment.
While I've used multi-strings before, I haven't thought too much about this case until now... AFAICT the correct way to represent an empty list is just a single null character: https://devblogs.microsoft.com/oldnewthing/20091008-00/?p=16443
Makes sense as empty strings cannot be present in a multi-string in the general case.
cb07d86 to
64f6145
Compare
|
Format fixed. For the empty multistring: Windows automatically pads REG_MULTI_SZ to 4 bytes minimum. Writing 1 null for |
Adds set_value_multistring_nothrow(), the missing nothrow counterpart to set_value_multistring(). Takes an array of null-terminated strings as (PCWSTR* data, size_t count) so it works in both exception-free and no-STL builds. Marshaling is done by an exceptions-free helper that allocates via unique_process_heap_ptr and builds the null-delimited, double-null terminated REG_MULTI_SZ buffer directly, with no std::vector or try/CATCH_RETURN(). Two overloads matching the existing pattern (with and without a subkey). Fixes microsoft#479 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3c550c3 to
ff19b42
Compare
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