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.
This commit is contained in:
Paul Sokolovsky
2017-01-17 22:50:20 +03:00
parent 5e80c53c11
commit af90461931
4 changed files with 17 additions and 7 deletions

View File

@@ -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;
}