Skip to content

Commit f325bd8

Browse files
author
Matt Wozniski
committed
Use OverflowError exception type for overflows
Initially I used one of the existing exception raise functions, but it's more correct and not much more code to raise OverflowError instead.
1 parent 095c844 commit f325bd8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

py/objint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s
340340
return;
341341

342342
raise:
343-
mp_raise_ValueError_varg(translate("value would overflow a %d byte buffer"), nbytes);
343+
mp_raise_OverflowError_varg(translate("value would overflow a %d byte buffer"), nbytes);
344344
}
345345

346346
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE

py/runtime.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,14 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt,
15981598
nlr_raise(exception);
15991599
}
16001600

1601+
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...) {
1602+
va_list argptr;
1603+
va_start(argptr,fmt);
1604+
mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_OverflowError, fmt, argptr);
1605+
va_end(argptr);
1606+
nlr_raise(exception);
1607+
}
1608+
16011609
NORETURN void mp_raise_MpyError(const compressed_string_t *msg) {
16021610
mp_raise_msg(&mp_type_MpyError, msg);
16031611
}

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
163163
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
164164
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
165165
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
166+
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
166167
NORETURN void mp_raise_MpyError(const compressed_string_t *msg);
167168
NORETURN void mp_raise_recursion_depth(void);
168169

0 commit comments

Comments
 (0)