]> Repositorios git - scryer-prolog.git/commitdiff
don't allow [] as a stream alias, restore domain error on source sink for open/{3,4}
authorMark Thom <[email protected]>
Sun, 28 Nov 2021 21:53:39 +0000 (14:53 -0700)
committerMark Thom <[email protected]>
Fri, 7 Jan 2022 04:44:41 +0000 (21:44 -0700)
src/machine/streams.rs
src/machine/system_calls.rs

index 8e2e2c1350288495a46d8f408163697f20a7b3da..047f91122983a1f281bf24dd1537d07033d479af 100644 (file)
@@ -1231,7 +1231,12 @@ impl MachineState {
         let alias = read_heap_cell!(self.store(MachineState::deref(self, alias)),
             (HeapCellValueTag::Atom, (name, arity)) => {
                 debug_assert_eq!(arity, 0);
-                Some(name)
+
+                if name != atom!("[]") {
+                    Some(name)
+                } else {
+                    None
+                }
             }
             _ => {
                 None
index 3d33d92123c6c53fa0d680f5e37a6ac806e9c8dc..2d699a064f646bfcac24cfce4fe4f57c69cc5827 100644 (file)
@@ -2977,8 +2977,16 @@ impl MachineState {
                 let options  = self.to_stream_options(alias, eof_action, reposition, stream_type);
                 let src_sink = self.store(self.deref(self.registers[1]));
 
-                if let Some(atom_or_string) = self.value_to_str_like(src_sink) {
-                    let file_spec  = self.atom_tbl.build_with(atom_or_string.as_str());
+                if let Some(str_like) = self.value_to_str_like(src_sink) {
+                    let file_spec = match str_like {
+                        AtomOrString::Atom(atom) => {
+                            atom
+                        }
+                        AtomOrString::String(string) => {
+                            self.atom_tbl.build_with(&string)
+                        }
+                    };
+
                     let mut stream = self.stream_from_file_spec(file_spec, indices, &options)?;
 
                     *stream.options_mut() = options;