Chris00 / ocaml-csv

CSV library for OCaml
Other
136 stars 22 forks source link

fix bug when buffer gets refilled in examine_quoted_field #7

Closed struktured closed 9 years ago

struktured commented 9 years ago

This took a while to find because Bytes.unsafe_get silently returned garbage whenever the buffer got refilled and the index was out of bounds.

Also, I'm not sure what happens if ic.in0 = ic.in1 = 0. If this would ever happen in that code path it might lead to undefined behavior.

Chris00 commented 9 years ago

You're right, I forgot that the initial index may change when filling the buffer. I will recheck the code.

According to the documentation of fill_in_buf_or_Eof, in0 = in1 = 0 can only occur on non-blocking channels. It is not propagated upward though. (If you really need non-blocking channels, the whole library needs to be revisited — one may try to factor it so functions can be used both on blocking channels but also with Lwt or Async).

Chris00 commented 9 years ago

May you please test again?

struktured commented 9 years ago

Tested using your own version of the fix and seems to work fine. Thanks.

Chris00 commented 9 years ago

It amounts to the same as your fix but I wanted to code to insist on the fact that ic.in0 is the important variable to consider — instead of "hiding" it behind i! ;-)