diff --git a/extmod/modure.c b/extmod/modure.c index 78de4706d27d9..3358b8e210e79 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -144,7 +144,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { } mp_obj_t retval = mp_obj_new_list(0, NULL); - const char **caps = alloca(caps_num * sizeof(char*)); + const char* caps[caps_num]; while (true) { // cast is a workaround for a bug in msvc: it treats const char** as a const pointer instead of a pointer to pointer to const char memset((char**)caps, 0, caps_num * sizeof(char*)); diff --git a/py/runtime.c b/py/runtime.c index cbec82f17c7a6..7a16e4a1b2f07 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1428,9 +1428,10 @@ mp_obj_t mp_import_from(mp_obj_t module, qstr name) { mp_load_method_maybe(module, MP_QSTR___name__, dest); size_t pkg_name_len; const char *pkg_name = mp_obj_str_get_data(dest[0], &pkg_name_len); - const uint dot_name_len = pkg_name_len + 1 + qstr_len(name); - char *dot_name = alloca(dot_name_len); + // Previously dot_name was created using alloca(), but that caused run-time crashes on M4 due to + // stack corruption (compiler bug, it appears), so use an array instead. + char dot_name[dot_name_len]; memcpy(dot_name, pkg_name, pkg_name_len); dot_name[pkg_name_len] = '.'; memcpy(dot_name + pkg_name_len + 1, qstr_str(name), qstr_len(name));