Commit ede0f3ab authored by Damien George's avatar Damien George
Browse files

py: Add optional code to check bytes constructor values are in range.

Compiled in only if MICROPY_CPYTHON_COMPAT is set.

Addresses issue #1093.
parent fd787c5e
......@@ -222,7 +222,13 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
mp_obj_t iterable = mp_getiter(args[0]);
mp_obj_t item;
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
vstr_add_byte(&vstr, mp_obj_get_int(item));
mp_int_t val = mp_obj_get_int(item);
if (val < 0 || val > 255) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bytes value out of range"));
vstr_add_byte(&vstr, val);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment