Skip to content

Commit

Permalink
Fix #20 : invalid serialization
Browse files Browse the repository at this point in the history
of (`Int min_int) because abs min_int < 0
  • Loading branch information
mjambon committed Sep 4, 2015
1 parent ad7027d commit cda6976
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion test.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
],
"'NULL' U+0000": "\u0000",
"'VULGAR FRACTION ONE HALF' U+00BD": "\u00BD",
"'PILE OF POO' U+1F4A9": "\uD83D\uDCA9"
"'PILE OF POO' U+1F4A9": "\uD83D\uDCA9",
"min_int": "-4611686018427387904"
}
4 changes: 2 additions & 2 deletions write.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let rec write_digits s pos x =
else
let d = x mod 10 in
let pos = write_digits s pos (x / 10) in
s.[pos] <- dec d;
s.[pos] <- dec (abs d);
pos + 1

let write_int ob x =
Expand All @@ -96,7 +96,7 @@ let write_int ob x =
let s = ob.o_s in
let pos = ob.o_len in
s.[pos] <- '-';
ob.o_len <- write_digits s (pos + 1) (abs x)
ob.o_len <- write_digits s (pos + 1) x
)
else
Bi_outbuf.add_char ob '0'
Expand Down

0 comments on commit cda6976

Please sign in to comment.