Skip to content

Commit 2e109bf

Browse files
committed
fix bug causing literally everything to crash and burn
1 parent e8416a4 commit 2e109bf

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/instruction/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,26 @@ impl InstructionSet {
104104
let mut current_idx = start_idx;
105105

106106
loop {
107+
// if we have calculated all buffer bounds, break
107108
if current_idx >= self.binary.len() - 1 {
108109
break;
109110
}
110111

112+
// set current_idx to starting index
113+
current_idx = start_idx;
114+
115+
// otherwise we'll keep the maximum end bound (e.g. current_idx + 4096)
111116
let max_end_idx = (start_idx + max_chunk_size).min(self.binary.len() - 1); // max end bound
112-
let mut last_valid_max = current_idx; // last valid end bound
117+
let mut last_valid_max = current_idx; // last valid end bound, we'll initialise
118+
// this to the current index
113119

120+
// while we're within the buffer bounds, keep incrementing the current_idx
114121
while current_idx < max_end_idx {
122+
if(current_idx > 1) { last_valid_max = current_idx - 1; } // keep reference to last valid max here
123+
124+
// then we "test the waters" by increment current_idx, this COULD be reset if
125+
// it goes over the max_end_idx
115126
current_idx += 4;
116-
117127
if self.get_binary()[current_idx] == 0x0C {
118128
current_idx += 1;
119129
} else if self.get_binary()[current_idx] == 0x0A {
@@ -133,16 +143,15 @@ impl InstructionSet {
133143
} else {
134144
return Err(InstructionError::IncompleteInstructions(self.get_binary()[current_idx]));
135145
}
136-
137-
138-
last_valid_max = current_idx - 1;
139146
}
140147

141148
chunk_bounds.push((start_idx, last_valid_max));
149+
println!("added: {} {}", start_idx, last_valid_max);
142150
start_idx = last_valid_max + 1;
143-
144151
}
145152

153+
println!("Buffer bounds: {:?}", chunk_bounds);
154+
146155
Ok(chunk_bounds)
147156
})
148157
}

0 commit comments

Comments
 (0)