summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-01-17 22:50:20 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-01-17 22:53:06 +0300
commitaf9046193148084f008501434e4c9f49fedc053f (patch)
tree7a05a10f74c645a5154f877c14eebbae25bd45f3 /py
parent5e80c53c115e8b45df598ffdbc45dfdd543be8ac (diff)
downloadmicropython-af9046193148084f008501434e4c9f49fedc053f.tar.gz
micropython-af9046193148084f008501434e4c9f49fedc053f.zip
py/binary: mp_binary_get_size: Raise error on unsupported typecodes.
Previouly, we had errors checked in callers, which led to duplicate code or missing checks in some places.
Diffstat (limited to 'py')
-rw-r--r--py/binary.c6
-rw-r--r--py/modstruct.c3
-rw-r--r--py/objarray.c3
3 files changed, 6 insertions, 6 deletions
diff --git a/py/binary.c b/py/binary.c
index d22e0f342d..6450478cc1 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -33,6 +33,7 @@
#include "py/binary.h"
#include "py/smallint.h"
#include "py/objint.h"
+#include "py/runtime.h"
// Helpers to work with binary-encoded data
@@ -100,6 +101,11 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
}
}
}
+
+ if (size == 0) {
+ mp_raise_ValueError("bad typecode");
+ }
+
if (palign != NULL) {
*palign = align;
}
diff --git a/py/modstruct.c b/py/modstruct.c
index 88411ff0fc..3c99ef1d8d 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -113,9 +113,6 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
} else {
mp_uint_t align;
size_t sz = mp_binary_get_size(fmt_type, *fmt, &align);
- if (sz == 0) {
- mp_raise_ValueError("unsupported format");
- }
while (cnt--) {
// Apply alignment
size = (size + align - 1) & ~(align - 1);
diff --git a/py/objarray.c b/py/objarray.c
index 8e1d32f0f4..ed666df8f0 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -94,9 +94,6 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
int typecode_size = mp_binary_get_size('@', typecode, NULL);
- if (typecode_size == 0) {
- mp_raise_msg(&mp_type_ValueError, "bad typecode");
- }
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
o->base.type = (typecode == BYTEARRAY_TYPECODE) ? &mp_type_bytearray : &mp_type_array;