summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-12-08 19:19:34 -0500
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-12-10 17:35:19 -0500
commitc8d44056b60c0e790da58fc1cfc22a77a4099023 (patch)
tree8b456ecaa6e454d0abe32f0f4ee5c272b1ab5ac6 /rust
parent2c7ba495a6c1d8b3639b74334b0cdd1809af807e (diff)
[Rust] Make `InstructionTextToken` field `expr_index` optional
There was a TODO there to document that it is optional, we should just wrap it in `Option` instead.
Diffstat (limited to 'rust')
-rw-r--r--rust/src/disassembly.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs
index b5980006..138bcd8a 100644
--- a/rust/src/disassembly.rs
+++ b/rust/src/disassembly.rs
@@ -19,11 +19,11 @@ use crate::architecture::Architecture;
use crate::architecture::CoreArchitecture;
use crate::basic_block::BasicBlock;
use crate::function::{Location, NativeBlock};
-use crate::high_level_il as hlil;
use crate::low_level_il as llil;
use crate::medium_level_il as mlil;
use crate::string::IntoCStr;
use crate::string::{raw_to_string, strings_to_string_list, BnString};
+use crate::{high_level_il as hlil, BN_INVALID_EXPR};
use crate::rc::*;
@@ -266,8 +266,7 @@ pub struct InstructionTextToken {
pub text: String,
pub confidence: u8,
pub context: InstructionTextTokenContext,
- // TODO: Document that this is not necessary to set and that this is valid in a limited context.
- pub expr_index: usize,
+ pub expr_index: Option<usize>,
pub kind: InstructionTextTokenKind,
}
@@ -278,7 +277,10 @@ impl InstructionTextToken {
text: raw_to_string(value.text).unwrap(),
confidence: value.confidence,
context: value.context.into(),
- expr_index: value.exprIndex,
+ expr_index: match value.exprIndex {
+ BN_INVALID_EXPR => None,
+ index => Some(index),
+ },
kind: InstructionTextTokenKind::from_raw(value),
}
}
@@ -305,7 +307,7 @@ impl InstructionTextToken {
// NOTE: Expected to be freed with `InstructionTextToken::free_raw`.
typeNames: strings_to_string_list(&type_names),
namesCount: type_names.len(),
- exprIndex: value.expr_index,
+ exprIndex: value.expr_index.unwrap_or(BN_INVALID_EXPR),
}
}
@@ -326,7 +328,7 @@ impl InstructionTextToken {
text: text.into(),
confidence: MAX_CONFIDENCE,
context: InstructionTextTokenContext::Normal,
- expr_index: 0,
+ expr_index: None,
kind,
}
}
@@ -341,7 +343,7 @@ impl InstructionTextToken {
text: text.into(),
confidence: MAX_CONFIDENCE,
context: InstructionTextTokenContext::Normal,
- expr_index: 0,
+ expr_index: None,
kind,
}
}