From 7c5a8b0f50fc5300cb6e4f7566383a5c1c89a852 Mon Sep 17 00:00:00 2001 From: abc Date: Tue, 9 Dec 2025 23:58:26 +0800 Subject: [PATCH] fix: correct instruction index in calculate_size function - Fixed incorrect get() index from total_size + 1 to proper instruction index - Use enumerate() to get correct instruction index for prefetch optimization - Prevents array bounds errors and ensures correct next instruction prefetch Bug: Using total_size (byte count) as array index for instruction lookup Solution: Use enumerate() iterator index for proper instruction access --- src/trading/core/execution.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trading/core/execution.rs b/src/trading/core/execution.rs index 7e27598..22069a8 100644 --- a/src/trading/core/execution.rs +++ b/src/trading/core/execution.rs @@ -106,10 +106,10 @@ impl InstructionProcessor { pub fn calculate_size(instructions: &[Instruction]) -> usize { let mut total_size = 0; - for instr in instructions { + for (i, instr) in instructions.iter().enumerate() { // 预取下一条指令 unsafe { - if let Some(next_instr) = instructions.get(total_size + 1) { + if let Some(next_instr) = instructions.get(i + 1) { BranchOptimizer::prefetch_read_data(next_instr); } }