Skip to content
Snippets Groups Projects
Commit 53461deb authored by Tom Collins's avatar Tom Collins Committed by Paul Sokolovsky
Browse files

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

Existing code failed if seek() went past EOF (which is acceptable when writing).
parent d5713c86
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,9 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er ...@@ -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; (void)errcode;
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in); mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
check_stringio_is_open(o); 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; mp_uint_t remaining = o->vstr->len - o->pos;
if (size > remaining) { if (size > remaining) {
size = remaining; size = remaining;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment