-
Notifications
You must be signed in to change notification settings - Fork 583
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Summary
When using PWCSTR and PWSTR on non-windows targets, wcslen is incorrectly used to determine the length of a null-terminated string.
The as_wide implementations needs to be fixed in one of the following ways:
- It could be disabled on non-windows targets
- It could instantly panic on non-windows targets
- It could be fixed to correctly count the non-zero
u16characters on non-windows targets
Crate manifest
[package]
name = "windows-test"
version = "0.1.0"
edition = "2021"
[dependencies]
windows-core = "0.56.0"Crate code
use windows_core::PCWSTR;
fn main() {
let arr = [b'a' as u16, b'b' as u16, 0, 0];
let s = PCWSTR::from_raw(&arr as *const u16);
let slice = unsafe { s.as_wide() };
// Should output [97, 98]
// Outputs [97] on Linux
println!("{:?}", slice);
let arr = [b'a' as u16, 0];
let s = PCWSTR::from_raw(&arr as *const u16);
let slice = unsafe { s.as_wide() };
// Should output [97]
// UB on Linux
println!("{:?}", slice);
}Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested