From f4dee20d0a6f639c538ddfff66c4d1c737b92e87 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Mon, 10 Oct 2022 14:20:30 +0200 Subject: [PATCH] Berry regex `re` fix --- lib/libesp32/berry/default/be_re_lib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/libesp32/berry/default/be_re_lib.c b/lib/libesp32/berry/default/be_re_lib.c index f725b9559..87ec811a3 100644 --- a/lib/libesp32/berry/default/be_re_lib.c +++ b/lib/libesp32/berry/default/be_re_lib.c @@ -67,6 +67,7 @@ const char *be_re_match_search_run(bvm *vm, ByteProg *code, const char *hay, bbo int sub_els = (code->sub + 1) * 2; const char *sub[sub_els]; + memset(sub, 0, sub_els * sizeof sub[0]); if (!re1_5_recursiveloopprog(code, &subj, sub, sub_els, is_anchored)) { be_pushnil(vm); @@ -74,12 +75,13 @@ const char *be_re_match_search_run(bvm *vm, ByteProg *code, const char *hay, bbo } be_newobject(vm, "list"); - int k; - for(k = sub_els; k > 0; k--) - if(sub[k-1]) - break; + int k = sub_els; for (int i = 0; i < k; i += 2) { + if (sub[i] == nil || sub[i+1] == nil) { + be_pushnil(vm); + } else { be_pushnstring(vm, sub[i], sub[i+1] - sub[i]); + } be_data_push(vm, -2); be_pop(vm, 1); }