1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-24 08:58:46 +00:00

fix(core/rust): fix overflow in tests by properly using 0-terminated strings

[no changelog]
This commit is contained in:
matejcik 2022-06-09 12:48:24 +02:00 committed by matejcik
parent b4145b69a3
commit c7b6e8986e

View File

@ -96,33 +96,40 @@ impl Wordlist {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use cstr_core::cstr;
const BIP39_WORD_COUNT: usize = ffi::BIP39_WORD_COUNT as usize; const BIP39_WORD_COUNT: usize = ffi::BIP39_WORD_COUNT as usize;
#[test] #[test]
fn test_prefix_cmp() { fn test_prefix_cmp() {
assert_eq!(unsafe { prefix_cmp("", "".as_ptr() as _) }, Ordering::Equal);
assert_eq!(unsafe { prefix_cmp("b", "".as_ptr() as _) }, Ordering::Less);
assert_eq!( assert_eq!(
unsafe { prefix_cmp("b", "a".as_ptr() as _) }, unsafe { prefix_cmp("", cstr!("").as_ptr()) },
Ordering::Equal
);
assert_eq!(
unsafe { prefix_cmp("b", cstr!("").as_ptr()) },
Ordering::Less Ordering::Less
); );
assert_eq!( assert_eq!(
unsafe { prefix_cmp("b", "b".as_ptr() as _) }, unsafe { prefix_cmp("b", cstr!("a").as_ptr()) },
Ordering::Less
);
assert_eq!(
unsafe { prefix_cmp("b", cstr!("b").as_ptr()) },
Ordering::Equal Ordering::Equal
); );
assert_eq!( assert_eq!(
unsafe { prefix_cmp("b", "below".as_ptr() as _) }, unsafe { prefix_cmp("b", cstr!("below").as_ptr()) },
Ordering::Equal Ordering::Equal
); );
assert_eq!( assert_eq!(
unsafe { prefix_cmp("b", "c".as_ptr() as _) }, unsafe { prefix_cmp("b", cstr!("c").as_ptr()) },
Ordering::Greater Ordering::Greater
); );
assert_eq!( assert_eq!(
unsafe { prefix_cmp("bartender", "bar".as_ptr() as _) }, unsafe { prefix_cmp("bartender", cstr!("bar").as_ptr()) },
Ordering::Less Ordering::Less
); );
} }