From: Alan T. DeKok Date: Tue, 18 Mar 2025 09:31:47 +0000 (+0700) Subject: move to new syntax X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32f677a3fbaa7adb8338320bbd66feda8ef7be22;p=thirdparty%2Ffreeradius-server.git move to new syntax and fix crash on nothing to loop over --- diff --git a/src/lib/unlang/foreach.c b/src/lib/unlang/foreach.c index ae1abd172f1..4dd56b1b916 100644 --- a/src/lib/unlang/foreach.c +++ b/src/lib/unlang/foreach.c @@ -163,8 +163,7 @@ static int _free_unlang_frame_state_foreach(unlang_frame_state_foreach_t *state) * Now that we're done, the leaf entries can be changed again. */ vp = tmpl_dcursor_init(NULL, NULL, &state->cc, &state->cursor, state->request, state->vpt); - fr_assert(vp != NULL); - + if (!vp) return 0; do { vp->vp_edit = false; } while ((vp = fr_dcursor_next(&state->cursor)) != NULL); diff --git a/src/tests/keywords/foreach-break b/src/tests/keywords/foreach-break index 268430f3253..fb01aad89fc 100644 --- a/src/tests/keywords/foreach-break +++ b/src/tests/keywords/foreach-break @@ -8,17 +8,17 @@ request += { Filter-Id = "broken" } -foreach Filter-Id { +foreach thing (Filter-Id) { # # If we see this one, "break" out of the # foreach loop. # - if ("%{Foreach-Variable-0}" == "broken") { + if (thing == "broken") { break } reply += { - Called-Station-Id = "%{Foreach-Variable-0}" + Called-Station-Id = thing } } @@ -31,8 +31,8 @@ request += { Filter-Id = "2" } -foreach Reply-Message { - if ("%{Foreach-Variable-0}" == "1") { +foreach thing (Reply-Message) { + if (thing == "1") { request += { Filter-Id = "3" } @@ -51,14 +51,14 @@ request += { Filter-Id = "2" } -foreach Reply-Message { - if ("%{Foreach-Variable-0}" == "1") { +foreach thing (Reply-Message) { + if (thing == "1") { request += { Filter-Id = "3" } } - if ("%{Foreach-Variable-0}" == "3") { + if (thing == "3") { break } }