]> Repositorios git - scryer-prolog.git/commitdiff
fix parser bounds check bug (#1333, #1301)
authorMark Thom <[email protected]>
Wed, 9 Mar 2022 04:25:19 +0000 (21:25 -0700)
committerMark Thom <[email protected]>
Wed, 9 Mar 2022 04:25:19 +0000 (21:25 -0700)
src/machine/system_calls.rs
src/parser/parser.rs
src/types.rs

index c435503dd1009655ee3d5cd8a7ac6f0a2f9c8dfe..5e23e19ec0e0158217a2096ab882489fd2034301 100644 (file)
@@ -3302,8 +3302,8 @@ impl Machine {
             .get_name();
 
         let op = read_heap_cell!(self.machine_st.store(self.machine_st.deref(op)),
-            (HeapCellValueTag::Char) => {
-                self.machine_st.atom_tbl.build_with(&op.to_string())
+            (HeapCellValueTag::Char, c) => {
+                self.machine_st.atom_tbl.build_with(&c.to_string())
             }
             (HeapCellValueTag::Atom, (name, _arity)) => {
                 name
index 2d6334c008af66664d291f33c6b9ce30e85c4b37..45f98ab84da3b9424e0e1541be5fe10eb2d57428 100644 (file)
@@ -823,13 +823,13 @@ impl<'a, R: CharRead> Parser<'a, R> {
 
         self.reduce_op(1400);
 
-        if self.stack.len() == 1 {
+        if self.stack.len() <= 1 {
             return false;
         }
 
         let idx = self.stack.len() - 2;
-
         let td = self.stack.remove(idx);
+
         match td.tt {
             TokenType::Open | TokenType::OpenCT => {
                 if self.stack[idx].tt == TokenType::Comma {
index b151ee23d9f8bcabd729e6dda5eb67f179bf35bf..0c2f289dbf990af1579359c95be1a8564c5eada6 100644 (file)
@@ -5,9 +5,6 @@ use crate::machine::machine_indices::*;
 use crate::machine::partial_string::PartialString;
 use crate::machine::streams::*;
 use crate::parser::ast::Fixnum;
-use crate::parser::rug::{Integer, Rational};
-
-use ordered_float::OrderedFloat;
 
 use std::cmp::Ordering;
 use std::convert::TryFrom;
@@ -244,56 +241,6 @@ pub struct HeapCellValue {
     tag: HeapCellValueTag,
 }
 
-impl fmt::Display for HeapCellValue {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        read_heap_cell!(*self,
-            (HeapCellValueTag::Atom, (name, arity)) => {
-                if arity == 0 {
-                    write!(f, "{}", name.as_str())
-                } else {
-                    write!(
-                        f,
-                        "{}/{}",
-                        name.as_str(),
-                        arity
-                    )
-                }
-            }
-            (HeapCellValueTag::PStr, pstr_atom) => {
-                let pstr = PartialString::from(pstr_atom);
-
-                write!(
-                    f,
-                    "pstr ( \"{}\", )",
-                    pstr.as_str_from(0)
-                )
-            }
-            (HeapCellValueTag::Cons, c) => {
-                match_untyped_arena_ptr!(c,
-                     (ArenaHeaderTag::Integer, n) => {
-                         write!(f, "{}", n)
-                     }
-                     (ArenaHeaderTag::Rational, r) => {
-                         write!(f, "{}", r)
-                     }
-                     (ArenaHeaderTag::F64, fl) => {
-                         write!(f, "{}", fl)
-                     }
-                     (ArenaHeaderTag::Stream, stream) => {
-                         write!(f, "$stream({})", stream.as_ptr() as usize)
-                     }
-                     _ => {
-                         write!(f, "")
-                     }
-                )
-            }
-            _ => {
-                unreachable!()
-            }
-        )
-    }
-}
-
 impl fmt::Debug for HeapCellValue {
     fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
         match self.get_tag() {