From 648ec675f46ddb4735ad6d33ec988a376c792219 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Wed, 16 May 2018 14:27:51 +0200 Subject: [PATCH] embed/extmod: add trezor_obj_get_uint8 --- embed/extmod/trezorobj.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/embed/extmod/trezorobj.h b/embed/extmod/trezorobj.h index 2bd3a2fe97..76ff4d4c5d 100644 --- a/embed/extmod/trezorobj.h +++ b/embed/extmod/trezorobj.h @@ -69,4 +69,12 @@ static inline mp_uint_t trezor_obj_get_uint(mp_obj_t obj) { } } +static inline uint8_t trezor_obj_get_uint8(mp_obj_t obj) { + mp_uint_t u = trezor_obj_get_uint(obj); + if (u > 0xFF) { + mp_raise_msg(&mp_type_OverflowError, "value does not fit into byte type"); + } + return u; +} + #endif