From 799007bbfee05ee706a9d24d399458c2229ad6af Mon Sep 17 00:00:00 2001 From: polwex Date: Tue, 7 Oct 2025 00:14:45 +0700 Subject: and he fixed the mugs --- ocaml/lib/noun.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ocaml/lib/noun.ml b/ocaml/lib/noun.ml index f4c4f87..382c79d 100644 --- a/ocaml/lib/noun.ml +++ b/ocaml/lib/noun.ml @@ -182,9 +182,15 @@ let rec mug noun = end and compute_mug_atom z = - (* Convert to bytes (little-endian, strip trailing zeros) *) + (* Convert to bytes (little-endian) *) let bytes = Z.to_bits z in - mug_bytes_with_seed bytes 0xcafebabel + (* Strip trailing zeros like C's u3r_mug_words does *) + let len = ref (String.length bytes) in + while !len > 0 && bytes.[!len - 1] = '\x00' do + decr len + done; + let stripped = String.sub bytes 0 !len in + mug_bytes_with_seed stripped 0xcafebabel (** Pretty-print a noun *) let rec pp_noun fmt = function -- cgit v1.2.3