Skip to content

Commit

Permalink
Buffer: actually enforce the invariant that (b.position <= b.length)
Browse files Browse the repository at this point in the history
See ocaml#8596 (comment)
and the rest of the conversation.
  • Loading branch information
gasche committed Apr 8, 2019
1 parent 24b54fe commit 39c443e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stdlib/buffer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ let really_input_up_to ic buf ofs len =
let unsafe_add_channel_up_to b ic len =
if b.position + len > b.length then resize b len;
let n = really_input_up_to ic b.buffer b.position len in
(* The assertion below may fail in weird scenario where
threaded/finalizer code races on the buffer; we don't
support these use-cases, but we want to at least
preserve the invariant. *)
assert (b.position + n <= b.length);
b.position <- b.position + n;
n

Expand Down

0 comments on commit 39c443e

Please sign in to comment.