Skip to content

Commit 771dfb0

Browse files
committed
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.
1 parent 1f53ff6 commit 771dfb0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

py/modbuiltins.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
137137
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
138138
#if MICROPY_PY_BUILTINS_STR_UNICODE
139139
mp_uint_t c = mp_obj_get_int(o_in);
140-
char str[4];
140+
uint8_t str[4];
141141
int len = 0;
142142
if (c < 0x80) {
143143
*str = c; len = 1;
@@ -159,12 +159,12 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
159159
} else {
160160
mp_raise_ValueError("chr() arg not in range(0x110000)");
161161
}
162-
return mp_obj_new_str_via_qstr(str, len);
162+
return mp_obj_new_str_via_qstr((char*)str, len);
163163
#else
164164
mp_int_t ord = mp_obj_get_int(o_in);
165165
if (0 <= ord && ord <= 0xff) {
166-
char str[1] = {ord};
167-
return mp_obj_new_str_via_qstr(str, 1);
166+
uint8_t str[1] = {ord};
167+
return mp_obj_new_str_via_qstr((char*)str, 1);
168168
} else {
169169
mp_raise_ValueError("chr() arg not in range(256)");
170170
}

0 commit comments

Comments
 (0)