Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 53461de

Browse files
tomlogicPaul Sokolovsky
authored and
Paul Sokolovsky
committed
py/objstringio: Fix StringIO reads at or beyond EOF.
Existing code failed if seek() went past EOF (which is acceptable when writing).
1 parent d5713c8 commit 53461de

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

py/objstringio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
5656
(void)errcode;
5757
mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in);
5858
check_stringio_is_open(o);
59+
if (o->vstr->len <= o->pos) { // read to EOF, or seeked to EOF or beyond
60+
return 0;
61+
}
5962
mp_uint_t remaining = o->vstr->len - o->pos;
6063
if (size > remaining) {
6164
size = remaining;

0 commit comments

Comments
 (0)