From: Mark Thom Date: Thu, 10 Apr 2025 06:03:28 +0000 (-0700) Subject: do not allow strings containing null characters to be inlined (#2848) X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=d1409e4e837a621d5105ce46f218e5980dcecdb9;p=scryer-prolog.git do not allow strings containing null characters to be inlined (#2848) --- diff --git a/src/atom_table.rs b/src/atom_table.rs index 09922b17..c9abafb7 100644 --- a/src/atom_table.rs +++ b/src/atom_table.rs @@ -467,7 +467,7 @@ impl AtomTable { } pub fn build_with(atom_table: &AtomTable, string: &str) -> Atom { - if 0 < string.len() && string.len() <= INLINED_ATOM_MAX_LEN { + if 0 < string.len() && string.len() <= INLINED_ATOM_MAX_LEN && !string.contains('\u{0}') { return Atom::new_inlined(string); } diff --git a/src/loader.pl b/src/loader.pl index 2a5e9fb8..f2d77009 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -177,7 +177,6 @@ print_comma_separated_list([VN=_, VNEq | VNEqs]) :- filter_anonymous_vars([], []). filter_anonymous_vars([VN=V | VNEqs0], VNEqs) :- - '$debug_hook', ( atom_concat('_', _, VN) -> filter_anonymous_vars(VNEqs0, VNEqs) ; VNEqs = [VN=V | VNEqs1], diff --git a/src/types.rs b/src/types.rs index 08d3c642..2f568770 100644 --- a/src/types.rs +++ b/src/types.rs @@ -101,7 +101,8 @@ impl ConsPtr { #[inline(always)] pub fn as_ptr(self) -> *mut u8 { - unsafe { mem::transmute::<_, *mut u8>(self.ptr()) } + let addr: u64 = self.ptr(); + addr as usize as *mut _ } #[inline(always)] diff --git a/tests-pl/iso-conformity-tests.pl b/tests-pl/iso-conformity-tests.pl index eea347cc..10b85c10 100644 --- a/tests-pl/iso-conformity-tests.pl +++ b/tests-pl/iso-conformity-tests.pl @@ -761,8 +761,7 @@ test_171 :- writeq_term_to_chars("a", C), test_229 :- test_syntax_error("\"\\z.\"", syntax_error(missing_quote)). -test_300 :- '$debug_hook', - writeq_term_to_chars("\0\", C), +test_300 :- writeq_term_to_chars("\0\", C), C == "['\\x0\\']". test_172 :- X is 10.0** -323,