improve asm sucessor to deal with arbritary jumps#7568
improve asm sucessor to deal with arbritary jumps#7568
Conversation
PR SummaryMedium Risk Overview Updates liveness analysis and CFG reachability simplification to consume this new API; reachability now conservatively disables CFG simplification when successors are Written by Cursor Bugbot for commit 1327cf7. This will update automatically on new commits. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Off-by-one in assertion allows invalid index
- Changed the successors assertion to
index < ops.len()so invalid end/empty-slice indices are rejected before successor computation.
- Changed the successors assertion to
Or push these changes by commenting:
@cursor push ce836f34a4
Preview (ce836f34a4)
diff --git a/sway-core/src/asm_lang/virtual_ops.rs b/sway-core/src/asm_lang/virtual_ops.rs
--- a/sway-core/src/asm_lang/virtual_ops.rs
+++ b/sway-core/src/asm_lang/virtual_ops.rs
@@ -963,7 +963,7 @@
/// ECAL can do pretty much anything, but it executes the next instruction, if "$pc"
/// is not manipulated.
pub(crate) fn successors(&self, index: usize, ops: &[Op]) -> InstructionSuccessor {
- assert!(index <= ops.len());
+ assert!(index < ops.len());
match self {
VirtualOp::RET(..) | VirtualOp::RETD(..) | VirtualOp::RVRT(..) => {
InstructionSuccessor::Many(vec![])| /// ECAL can do pretty much anything, but it executes the next instruction, if "$pc" | ||
| /// is not manipulated. | ||
| pub(crate) fn successors(&self, index: usize, ops: &[Op]) -> InstructionSuccessor { | ||
| assert!(index <= ops.len()); |
There was a problem hiding this comment.
Off-by-one in assertion allows invalid index
Low Severity
The assertion assert!(index <= ops.len()) uses <= instead of <. Since index represents a valid instruction index into ops, the invariant is index < ops.len(). Using <= allows index == ops.len() to pass the assert silently. Worse, if ops is empty and index == 0, the assert passes but ops.len() - 1 on line 974 causes a usize underflow panic. With <, the assert would correctly catch both cases.
fa5d11d to
1327cf7
Compare



Description
Checklist
Breaking*orNew Featurelabels where relevant.