Revision: 3822 http://trac.macosforge.org/projects/ruby/changeset/3822 Author: lsansonetti@apple.com Date: 2010-03-18 20:39:43 -0700 (Thu, 18 Mar 2010) Log Message: ----------- fixed a bug in IO#gets when the separator is more than 1 character Modified Paths: -------------- MacRuby/trunk/io.c Modified: MacRuby/trunk/io.c =================================================================== --- MacRuby/trunk/io.c 2010-03-19 03:24:13 UTC (rev 3821) +++ MacRuby/trunk/io.c 2010-03-19 03:39:43 UTC (rev 3822) @@ -1344,9 +1344,9 @@ rb_bstr_resize(bstr, s); uint8_t *buf = rb_bstr_bytes(bstr); - uint8_t *tmp_buf = (uint8_t *)malloc(seplen); while (true) { - if (rb_io_read_internal(io_struct, tmp_buf, seplen) != seplen) { + uint8_t c = 0; + if (rb_io_read_internal(io_struct, &c, 1) != 1) { break; } if (data_read >= s) { @@ -1354,14 +1354,15 @@ rb_bstr_resize(bstr, s); buf = rb_bstr_bytes(bstr); } - memcpy(&buf[data_read], tmp_buf, seplen); - data_read += seplen; + buf[data_read] = c; + data_read += 1; - if (memcmp(tmp_buf, sepstr, seplen) == 0) { + if (data_read >= seplen + && memcmp(&buf[data_read - seplen], sepstr, + seplen) == 0) { break; } } - free(tmp_buf); if (data_read == 0) { return Qnil;
participants (1)
-
source_changes@macosforge.org