[asterisk-bugs] [Asterisk 0011957]: It appears that a true branch is executed even when ExecIf() returns false

noreply at bugs.digium.com noreply at bugs.digium.com
Fri Feb 8 12:33:04 CST 2008


A NOTE has been added to this issue. 
====================================================================== 
http://bugs.digium.com/view.php?id=11957 
====================================================================== 
Reported By:                blitzrage
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   11957
Category:                   Applications/app_exec
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
Asterisk Version:           1.4.17 
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Disclaimer on File?:        N/A 
Request Review:              
====================================================================== 
Date Submitted:             02-08-2008 11:29 CST
Last Modified:              02-08-2008 12:33 CST
====================================================================== 
Summary:                    It appears that a true branch is executed even when
ExecIf() returns false
Description: 
I'm opening this for a bit of discussion as I believe the following
conditions could result in inefficiencies in the dialplan.

I have the following bit of dialplan code:

exten => h,n,Verbose(1,DIALSTATUS = ${DIALSTATUS})
exten => h,n,ExecIf($[${DIALSTATUS} =
ANSWER],Set,TIME_USED=${MATH(${ANSWEREDTIME}/60,f)})


But when I execute it in the dialplan, I end up with this:

    -- Executing [h at subPlaceCall:2] Verbose("SIP/4918847473-1565e170",
"1|DIALSTATUS = CANCEL") in new stack
 DIALSTATUS = CANCEL
[Feb  8 12:21:51] WARNING[19032]: func_math.c:169 math: '' is not a valid
number
    -- Executing [h at subPlaceCall:3] ExecIf("SIP/4918847473-1565e170",
"0|Set|TIME_USED=") in new stack


Which appears to be that the MATH() function is being executed before the
condition is checked. That seems backwards to me in that the condition
should be checked before any action is taken on the arguments provided.

I've seen the same behaviour with the IF() function as well:

exten => h,n,Exec(${IF(${DIALSTATUS} =
ANSWER]?Set(TIME_USED=${MATH(${ANSWEREDTIME}/60,f)}):NoOp())})

Same behaviour happens where MATH() returns an error because
${ANSWEREDTIME} is not populated (and it shouldn't be -- the call was not
answered).
====================================================================== 

---------------------------------------------------------------------- 
 blitzrage - 02-08-08 12:33  
---------------------------------------------------------------------- 
Yes exactly. The dialplan functions are evaluated before the condition
statement is evaluated. This is essentially the same issue that I found,
except you replaced MATH() with SET().

i.e. the MATH() function was being executed, but returned an error because
the variable was null (${ANSWEREDTIME}), but the variable was not set
because the application was not executed (since that is done after the
condition is set).

But when you replaced the application with the function, then you were
evaluating the function before the condition was checked, and it didn't
even matter if the condition was true or not. In fact, you would have
executed SET() twice if it were true. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
02-08-08 12:33  blitzrage      Note Added: 0081932                          
======================================================================




More information about the asterisk-bugs mailing list