From 53461deb04ecddf3be8b8b03024bb8bbc08b9d6b Mon Sep 17 00:00:00 2001 From: Tom Collins Date: Fri, 12 May 2017 13:30:12 -0700 Subject: py/objstringio: Fix StringIO reads at or beyond EOF. Existing code failed if seek() went past EOF (which is acceptable when writing). --- py/objstringio.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'py') diff --git a/py/objstringio.c b/py/objstringio.c index 88659deb89..f4e7967807 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -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; -- cgit v1.2.3