On Fri Jan 19 22:20:34 2024 +0000, Krzysztof Bogacki wrote:
Indeed, but I thought it would be safer to allocate some memory for a temporary working area, try enumerating adapters and only copy the result if the entire operation did not fail halfway through rather than using the array I was passed by the caller directly and risk writing some partially misleading garbage to it. I also wasn't sure how to proceed in such case: if I already wrote some LUIDs and handles, should I try to `memset(0)` them just in case or leave the data there and trust that all callers of this API will ignore whatever was written, treating the content as unspecified? It's also somewhat tricky to cause Windows to fail here so I don't know how exactly does it behave when it encounters some error internally. Copying the full result only on full success seemed like an easy way out that allowed me to not bother figuring this out, even if it costs an extra allocation. But I can revert to writing to `pAdapters` directly if you'd prefer it that way.
If an error occurs, an error code is returned and the application shouldn't use the buffer. But just to be safe, you can do a memset(0) when it fails.