Skip to content

Commit

Permalink
avoid panicking (and thus causing sometimes a segfault) when deserial…
Browse files Browse the repository at this point in the history
…izing a native execution result (#329)
  • Loading branch information
edg-l authored Oct 26, 2023
1 parent e7170f4 commit 7ecb2ca
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/execution_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,22 @@ impl NativeExecutionResult {
.map(|felt_bytes| u32_vec_to_felt(felt_bytes))
.collect();

let str_error =
String::from_utf8(felt_error[0].to_be_bytes().to_vec())
.unwrap()
.trim_start_matches('\0')
.to_owned();
let str_error = String::from_utf8(
felt_error
.get(0)
.ok_or_else(|| {
de::Error::custom(
"error getting felt error message",
)
})?
.to_be_bytes()
.to_vec(),
)
.map_err(|_| {
de::Error::custom("error parsing error from utf8")
})?
.trim_start_matches('\0')
.to_owned();

Ok(NativeExecutionResult {
gas_consumed,
Expand Down

0 comments on commit 7ecb2ca

Please sign in to comment.