Skip to content

Commit be78726

Browse files
martin-hughesIsaacWoods
authored andcommitted
Fix ToInteger handling
1 parent e7ec83f commit be78726

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/aml/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,17 +1972,19 @@ where
19721972
* that won't fit in a `u64` etc. We probably need to write a more robust parser
19731973
* 'real' parser to handle those cases.
19741974
*/
1975-
if let Some(value) = value.strip_prefix("0x") {
1976-
let parsed = u64::from_str_radix(value, 16).map_err(|_| {
1975+
let value = value.trim();
1976+
let value = value.to_ascii_lowercase();
1977+
let (value, radix): (&str, u32) = match value.strip_prefix("0x") {
1978+
Some(value) => {
1979+
(value.split(|c: char| !c.is_ascii_hexdigit()).next().unwrap_or(""), 16)
1980+
}
1981+
None => (value.split(|c: char| !c.is_ascii_digit()).next().unwrap_or(""), 10),
1982+
};
1983+
match value.len() {
1984+
0 => Object::Integer(0),
1985+
_ => Object::Integer(u64::from_str_radix(value, radix).map_err(|_| {
19771986
AmlError::InvalidOperationOnObject { op: Operation::ToInteger, typ: ObjectType::String }
1978-
})?;
1979-
Object::Integer(parsed)
1980-
} else {
1981-
let parsed = str::parse::<u64>(value).map_err(|_| AmlError::InvalidOperationOnObject {
1982-
op: Operation::ToInteger,
1983-
typ: ObjectType::String,
1984-
})?;
1985-
Object::Integer(parsed)
1987+
})?),
19861988
}
19871989
}
19881990
_ => Err(AmlError::InvalidOperationOnObject { op: Operation::ToBuffer, typ: operand.typ() })?,

tests/to_integer.asl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,29 @@ DefinitionBlock ("", "SSDT", 2, "uTEST", "TESTTABL", 0xF0F0F0F0)
2020
Local1 = 123
2121
CHEK(Local0, Local1, __LINE__)
2222

23-
/* TODO: Restore commented out tests
2423
Local0 = ToInteger(" \t\t\t\v 123")
2524
Local1 = 123
2625
CHEK(Local0, Local1, __LINE__)
27-
*/
2826

29-
/*
3027
Local0 = ToInteger("123abcd")
3128
Local1 = 123
3229
CHEK(Local0, Local1, __LINE__)
33-
*/
3430

3531
Local0 = ToInteger("0x123abcd")
3632
Local1 = 0x123abcd
3733
CHEK(Local0, Local1, __LINE__)
3834

39-
/*
4035
Local0 = ToInteger("")
4136
Local1 = 0
4237
CHEK(Local0, Local1, __LINE__)
43-
*/
4438

45-
/*
4639
Local0 = ToInteger("0X")
4740
Local1 = 0
4841
CHEK(Local0, Local1, __LINE__)
49-
*/
5042

51-
/*
5243
Local0 = ToInteger("0x")
5344
Local1 = 0
5445
CHEK(Local0, Local1, __LINE__)
55-
*/
5646

5747
Local0 = ToInteger("0")
5848
Local1 = 0
@@ -62,11 +52,9 @@ DefinitionBlock ("", "SSDT", 2, "uTEST", "TESTTABL", 0xF0F0F0F0)
6252
Local1 = 0xDEADBEEF
6353
CHEK(Local0, Local1, __LINE__)
6454

65-
/*
6655
Local0 = ToInteger("0XDeAdBeeFCafeBabeHelloWorld")
6756
Local1 = 0xDEADBEEFCAFEBABE
6857
CHEK(Local0, Local1, __LINE__)
69-
*/
7058

7159
Local0 = ToInteger(Buffer { 0xDE, 0xAD, 0xBE, 0xEF })
7260
Local1 = 0xEFBEADDE

0 commit comments

Comments
 (0)