diff options
Diffstat (limited to 'ocaml')
-rw-r--r-- | ocaml/lib/noun.ml | 10 |
1 files 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 |