aboutsummaryrefslogtreecommitdiff
path: root/py/binary.c
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/binary.c
parent5e80c53c115e8b45df598ffdbc45dfdd543be8ac (diff)
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/binary.c')
-rw-r--r--py/binary.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/py/binary.c b/py/binary.c
index d22e0f342..6450478cc 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;
}