When we call a gosub routine, the variables should be scoped to avoid contaminating the caller.

This affected the ~~EXTEN~~ hack, where a subroutine might have changed the
value before it was used in the caller.
Patch by myself, tested by ebroad on #asterisk


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@222273 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/1.8.6
Tilghman Lesher 16 years ago
parent 0c3cd2ee45
commit 78012e4f71

@ -3361,38 +3361,60 @@ static void gen_prios(struct ael_extension *exten, char *label, pval *statement,
if (contains_switch(statement)) { /* only run contains_switch if you haven't checked before */ if (contains_switch(statement)) { /* only run contains_switch if you haven't checked before */
if (mother_exten) { if (mother_exten) {
if (!mother_exten->has_switch) { if (!mother_exten->has_switch) {
switch_set = new_prio(); for (first = 1; first >= 0; first--) {
switch_set->type = AEL_APPCALL; switch_set = new_prio();
if (!ast_compat_app_set) { switch_set->type = AEL_APPCALL;
switch_set->app = strdup("MSet"); if (!ast_compat_app_set) {
} else { switch_set->app = strdup("MSet");
switch_set->app = strdup("Set"); } else {
} switch_set->app = strdup("Set");
switch_set->appargs = strdup("~~EXTEN~~=${EXTEN}"); }
linkprio(exten, switch_set, mother_exten); /* Are we likely inside a gosub subroutine? */
mother_exten->has_switch = 1; if (!strcmp(mother_exten->name, "s") && first) {
mother_exten->checked_switch = 1; /* If we're not actually within a gosub, this will fail, but the
if (exten) { * second time through, it will get set. If we are within gosub,
exten->has_switch = 1; * the second time through is redundant, but acceptable. */
exten->checked_switch = 1; switch_set->appargs = strdup("LOCAL(~~EXTEN~~)=${EXTEN}");
} else {
switch_set->appargs = strdup("~~EXTEN~~=${EXTEN}");
first = 0;
}
linkprio(exten, switch_set, mother_exten);
mother_exten->has_switch = 1;
mother_exten->checked_switch = 1;
if (exten) {
exten->has_switch = 1;
exten->checked_switch = 1;
}
} }
} }
} else if (exten) { } else if (exten) {
if (!exten->has_switch) { if (!exten->has_switch) {
switch_set = new_prio(); for (first = 1; first >= 0; first--) {
switch_set->type = AEL_APPCALL; switch_set = new_prio();
if (!ast_compat_app_set) { switch_set->type = AEL_APPCALL;
switch_set->app = strdup("MSet"); if (!ast_compat_app_set) {
} else { switch_set->app = strdup("MSet");
switch_set->app = strdup("Set"); } else {
} switch_set->app = strdup("Set");
switch_set->appargs = strdup("~~EXTEN~~=${EXTEN}"); }
linkprio(exten, switch_set, mother_exten); /* Are we likely inside a gosub subroutine? */
exten->has_switch = 1; if (!strcmp(exten->name, "s")) {
exten->checked_switch = 1; /* If we're not actually within a gosub, this will fail, but the
if (mother_exten) { * second time through, it will get set. If we are within gosub,
mother_exten->has_switch = 1; * the second time through is redundant, but acceptable. */
mother_exten->checked_switch = 1; switch_set->appargs = strdup("LOCAL(~~EXTEN~~)=${EXTEN}");
} else {
switch_set->appargs = strdup("~~EXTEN~~=${EXTEN}");
first = 0;
}
linkprio(exten, switch_set, mother_exten);
exten->has_switch = 1;
exten->checked_switch = 1;
if (mother_exten) {
mother_exten->has_switch = 1;
mother_exten->checked_switch = 1;
}
} }
} }
} }

Loading…
Cancel
Save