8000 WIP py/objstr: Handle invalid iteration when constructing bytes. · micropython/micropython@b4710b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4710b4

Browse files
committed
WIP py/objstr: Handle invalid iteration when constructing bytes.
1 parent 4561694 commit b4710b4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

py/objstr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
256256
mp_obj_iter_buf_t iter_buf;
257257
mp_obj_t iterable = mp_getiter(args[0], &iter_buf);
258258
mp_obj_t item;
259-
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
259+
while ((item = mp_iternext2(iterable)) != MP_OBJ_NULL) {
260260
mp_int_t val = mp_obj_get_int(item);
261261
#if MICROPY_FULL_CHECKS
262262
if (val < 0 || val > 255) {
@@ -265,6 +265,9 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
265265
#endif
266266
vstr_add_byte(&vstr, val);
267267
}
268+
if (mp_iternext_had_exc()) {
269+
return MP_OBJ_NULL;
270+
}
268271

269272
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
270273

0 commit comments

Comments
 (0)
0