diff --git a/py/objint.c b/py/objint.c index fc672b1123..029402a8db 100644 --- a/py/objint.c +++ b/py/objint.c @@ -340,7 +340,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s return; raise: - mp_raise_ValueError_varg(translate("value would overflow a %d byte buffer"), nbytes); + mp_raise_OverflowError_varg(translate("value would overflow a %d byte buffer"), nbytes); } #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE diff --git a/py/runtime.c b/py/runtime.c index 1a75a3870b..9968f26e06 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1598,6 +1598,14 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, nlr_raise(exception); } +NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...) { + va_list argptr; + va_start(argptr,fmt); + mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_OverflowError, fmt, argptr); + va_end(argptr); + nlr_raise(exception); +} + NORETURN void mp_raise_MpyError(const compressed_string_t *msg) { mp_raise_msg(&mp_type_MpyError, msg); } diff --git a/py/runtime.h b/py/runtime.h index c5a94b0b19..e8398cf0ea 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -163,6 +163,7 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg); NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg); NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...); +NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_MpyError(const compressed_string_t *msg); NORETURN void mp_raise_recursion_depth(void);