py/objstringio: Fix regression with handling SEEK_SET.
For SEEK_SET, offset should be treated as unsigned, to allow full-width stream sizes (e.g. 32-bit instead of 31-bit). This is now fully documented in stream.h. Also, seek symbolic constants are added.
This commit is contained in:
@@ -118,15 +118,17 @@ STATIC mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
|
||||
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
|
||||
mp_uint_t ref = 0;
|
||||
switch (s->whence) {
|
||||
case 1: // SEEK_CUR
|
||||
case MP_SEEK_CUR:
|
||||
ref = o->pos;
|
||||
break;
|
||||
case 2: // SEEK_END
|
||||
case MP_SEEK_END:
|
||||
ref = o->vstr->len;
|
||||
break;
|
||||
}
|
||||
mp_uint_t new_pos = ref + s->offset;
|
||||
if (s->offset < 0) {
|
||||
|
||||
// For MP_SEEK_SET, offset is unsigned
|
||||
if (s->whence != MP_SEEK_SET && s->offset < 0) {
|
||||
if (new_pos > ref) {
|
||||
// Negative offset from SEEK_CUR or SEEK_END went past 0.
|
||||
// CPython sets position to 0, POSIX returns an EINVAL error
|
||||
|
||||
Reference in New Issue
Block a user