py/modbuiltins: For builtin_chr, use uint8_t instead of char for array.

The array should be of type unsigned byte because that is the type of the
values being stored.  And changing to uint8_t helps to prevent warnings
from some static analysers.
This commit is contained in:
Damien George 2018-02-07 16:10:42 +11:00
parent 1f53ff61ff
commit 771dfb0826
1 changed files with 4 additions and 4 deletions

View File

@ -137,7 +137,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
#if MICROPY_PY_BUILTINS_STR_UNICODE
mp_uint_t c = mp_obj_get_int(o_in);
char str[4];
uint8_t str[4];
int len = 0;
if (c < 0x80) {
*str = c; len = 1;
@ -159,12 +159,12 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
} else {
mp_raise_ValueError("chr() arg not in range(0x110000)");
}
return mp_obj_new_str_via_qstr(str, len);
return mp_obj_new_str_via_qstr((char*)str, len);
#else
mp_int_t ord = mp_obj_get_int(o_in);
if (0 <= ord && ord <= 0xff) {
char str[1] = {ord};
return mp_obj_new_str_via_qstr(str, 1);
uint8_t str[1] = {ord};
return mp_obj_new_str_via_qstr((char*)str, 1);
} else {
mp_raise_ValueError("chr() arg not in range(256)");
}