From: Jérémie Astor Date: Mon, 16 Aug 2021 07:23:00 +0000 (+0200) Subject: :bug: fix string.rfind X-Git-Tag: nightly~470^2~82 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=af88e5a6df0b1374b15ef0f4931c77c61c763e12;p=gwion.git :bug: fix string.rfind --- diff --git a/src/lib/string.c b/src/lib/string.c index 05c56d9a..1ca973e2 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -337,8 +337,8 @@ static MFUN(string_rfindStrStart) { const m_str base = STRING(o); const size_t sz = strlen(base); const char pos = *(m_int *)MEM(SZ_INT * 2); - const M_Object obj = *(M_Object *)MEM(SZ_INT * 2); - if (sz) { + const M_Object obj = *(M_Object *)MEM(SZ_INT); + if (sz && pos < sz) { const m_str arg = STRING(obj); m_str tmp = base + pos, str = NULL; while ((tmp = strstr(tmp, arg))) str = tmp++; diff --git a/tests/string/find.gw b/tests/string/find.gw index 6c42ccad..3b923f3c 100644 --- a/tests/string/find.gw +++ b/tests/string/find.gw @@ -2,25 +2,25 @@ <<< "test".find('a') >>>; <<< "".find('a') >>>; -<<< "test".find(-1, 'e') >>>; -<<< "test".find(0, 'e') >>>; -<<< "test".find(1, 'a') >>>; -<<< "".find(1, 'a') >>>; +<<< "test".find('e', -1) >>>; +<<< "test".find('e', 0) >>>; +<<< "test".find('a', 1) >>>; +<<< "".find('a', 0) >>>; <<< "test".find("es") >>>; <<< "test".find("a") >>>; <<< "".find("") >>>; -<<< "test".find(-1, "es") >>>; -<<< "test".find(0, "es") >>>; -<<< "test".find(1, "a") >>>; -<<< "".find(1, "") >>>; +<<< "test".find("es", -1) >>>; +<<< "test".find("es", 0) >>>; +<<< "test".find("a", 1) >>>; +<<< "".find("", 1) >>>; <<< "test".rfind("es") >>>; <<< "test".rfind("a") >>>; <<< "".rfind("") >>>; -<<< "test".rfind(-1, "es") >>>; -<<< "test".rfind(0, "e") >>>; -<<< "test".rfind(1, "a") >>>; -<<< "".rfind(1, "") >>>; +<<< "test".rfind("es", -1) >>>; +<<< "test".rfind("e", 0) >>>; +<<< "test".rfind("a", 1) >>>; +<<< "".rfind("", 1) >>>;