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 2 commits into
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. |
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
aa93024 to
da4b4db
Compare
Replace the try/CATCH_RETURN() implementation with an exceptions-free get_multistring_from_wstrings_nothrow helper so the API works in no-exception builds (guard broadened to WIL_USE_STL). Addresses review feedback: use unique_process_heap_ptr for ownership, single memcpy of size()+1 to include the terminator, and a WI_ASSERT size sanity check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| 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.
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