]> Repositorios git - scryer-prolog.git/commitdiff
fix off-by-one error caused logtalk test to crash
authorMark <[email protected]>
Thu, 21 Dec 2023 19:14:12 +0000 (12:14 -0700)
committerMark <[email protected]>
Thu, 21 Dec 2023 19:14:12 +0000 (12:14 -0700)
src/machine/compile.rs

index d1c3e016839a1ddb7944c5c45ee437dbbadb7762..68d4da1f78b195df748159005a04c913404ed4b9 100644 (file)
@@ -47,6 +47,8 @@ fn lower_bound_of_target_clause(skeleton: &mut PredicateSkeleton, target_pos: us
         return 0;
     }
 
+    debug_assert!(skeleton.clauses.len() >= 2);
+
     let index = target_pos - 1;
 
     let index = if let Some(index_loc) = skeleton.clauses[index]
@@ -68,7 +70,7 @@ fn lower_bound_of_target_clause(skeleton: &mut PredicateSkeleton, target_pos: us
         index
     };
 
-    index.clamp(0, skeleton.clauses.len() - 1)
+    index.clamp(0, skeleton.clauses.len() - 2)
 }
 
 fn derelictize_try_me_else(
@@ -1518,6 +1520,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
         } = self.compile_standalone_clause(clause, settings)?;
 
         let code_len = self.wam_prelude.code.len();
+
         standalone_skeleton.clauses[0].clause_start += code_len;
 
         let skeleton = match self