Skip to content

Commit 03d5426

Browse files
moulinsHerschel
authored andcommitted
wstr: statically check the size of WString
This adds the 'static_assertions' crate as a dependency of 'ruffle_wstr', but this dependency was already present in the dep tree.
1 parent 8806e99 commit 03d5426

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Cargo.lock

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wstr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ authors = ["Arthur Heuillard <arthur.heuillard<orange.fr>"]
66
license = "MIT OR Apache-2.0"
77

88
[dependencies]
9+
static_assertions = "1.1.0"

wstr/src/buf.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::fmt;
55
use core::mem::{self, ManuallyDrop};
66
use core::ops::{Deref, DerefMut};
77
use core::ptr::NonNull;
8+
use static_assertions::assert_eq_size;
89

910
use super::utils::{encode_raw_utf16, split_ascii_prefix, split_ascii_prefix_bytes, DecodeAvmUtf8};
1011
use super::{ptr, Units, WStr, MAX_STRING_LEN};
@@ -16,6 +17,12 @@ pub struct WString {
1617
capacity: u32,
1718
}
1819

20+
#[cfg(target_pointer_width = "32")]
21+
assert_eq_size!(WString, [u8; 12]);
22+
23+
#[cfg(target_pointer_width = "64")]
24+
assert_eq_size!(WString, [u8; 16]);
25+
1926
impl WString {
2027
/// Creates a new empty `WString`.
2128
#[inline]

0 commit comments

Comments
 (0)