py/objstringio: Fix StringIO reads at or beyond EOF.

Existing code failed if seek() went past EOF (which is acceptable when writing).
This commit is contained in:
Tom Collins 2017-05-12 13:30:12 -07:00 committed by Paul Sokolovsky
parent d5713c8618
commit 53461deb04
1 changed files with 3 additions and 0 deletions

View File

@ -56,6 +56,9 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
(void)errcode;
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
check_stringio_is_open(o);
if (o->vstr->len <= o->pos) { // read to EOF, or seeked to EOF or beyond
return 0;
}
mp_uint_t remaining = o->vstr->len - o->pos;
if (size > remaining) {
size = remaining;