contextfree / winrt-rust

Use and (eventually) make Windows Runtime APIs with Rust
Apache License 2.0
142 stars 10 forks source link

Don't construct a tmp slice with a null ptr #57

Closed hcs64 closed 5 years ago

hcs64 commented 5 years ago

According to the docs for std::slice::from_raw_parts, "data must be non-null and aligned, even for zero-length slices". Doesn't cause any issues currently, but it's worthwhile to be pedantic about nulls.

Boddlnagg commented 5 years ago

Nice catch, thanks! BStr is not used anywhere else in winrt-rust, so this change has not a big impact, but it might be a good idea to do the same thing in hstring.rs (internal_to_string), because WindowsGetStringRawBuffer can also return NULL (I just checked).

Boddlnagg commented 5 years ago

What I said above about WindowsGetStringRawBuffer was rubbish. It can't return NULL. But this PR is totally correct :)