Merge "ari: Implement 'debug all' and request/response logging"
[asterisk/asterisk.git] / funcs / func_math.c
index e7217c7..6fc7255 100644 (file)
@@ -34,8 +34,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include <math.h>
 
 #include "asterisk/module.h"
@@ -57,7 +55,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <replaceable>number1</replaceable><replaceable>op</replaceable><replaceable>number2</replaceable>
                                where the possible values for <replaceable>op</replaceable>
                                are:</para>
-                               <para>+,-,/,*,%,&lt;&lt;,&gt;&gt;,^,AND,OR,XOR,&lt;,%gt;,&gt;=,&lt;=,== (and behave as their C equivalents)</para>
+                               <para>+,-,/,*,%,&lt;&lt;,&gt;&gt;,^,AND,OR,XOR,&lt;,&gt;,&lt;=,&gt;=,== (and behave as their C equivalents)</para>
                        </parameter>
                        <parameter name="type">
                                <para>Wanted type of result:</para>
@@ -103,8 +101,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                </syntax>
                <description>
                        <para>Decrements the value of a variable, while returning the updated value to the dialplan</para>
-                       <para>Example: DEC(MyVAR) - Increments MyVar</para>
-                       <para>Note: DEC(${MyVAR}) - Is wrong, as INC expects the variable name, not its value</para>
+                       <para>Example: DEC(MyVAR) - Decrements MyVar</para>
+                       <para>Note: DEC(${MyVAR}) - Is wrong, as DEC expects the variable name, not its value</para>
                </description>
        </function>
  ***/
@@ -254,7 +252,7 @@ static int math(struct ast_channel *chan, const char *cmd, char *parse,
                }
        }
 
-       if (!mvalue1 || !mvalue2) {
+       if (!mvalue2) {
                ast_log(LOG_WARNING,
                                "Supply all the parameters - just this once, please\n");
                return -1;
@@ -392,6 +390,11 @@ static int crement_function_read(struct ast_channel *chan, const char *cmd,
                return -1;
        }
 
+       if (!chan) {
+               ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+               return -1;
+       }
+
        ast_channel_lock(chan);
 
        if (!(var = pbx_builtin_getvar_helper(chan, data))) {
@@ -421,8 +424,6 @@ static int crement_function_read(struct ast_channel *chan, const char *cmd,
                modify_orig = 1;
        }
 
-       ast_log(LOG_NOTICE, "The value is now: %d\n", int_value);
-
        if (snprintf(returnvar, sizeof(returnvar), "%d", int_value) > 0) {
                pbx_builtin_setvar_helper(chan, data, returnvar);
                if (modify_orig) {
@@ -479,13 +480,11 @@ AST_TEST_DEFINE(test_MATH_function)
 
        ast_test_status_update(test, "Testing MATH() substitution ...\n");
 
-       if (!(expr = ast_str_create(16)) || !(result = ast_str_create(16))) {
-               if (expr) {
-                       ast_free(expr);
-               }
-               if (result) {
-                       ast_free(result);
-               }
+       if (!(expr = ast_str_create(16))) {
+               return AST_TEST_FAIL;
+       }
+       if (!(result = ast_str_create(16))) {
+               ast_free(expr);
                return AST_TEST_FAIL;
        }
 
@@ -505,6 +504,9 @@ AST_TEST_DEFINE(test_MATH_function)
                res = AST_TEST_FAIL;
        }
 
+       ast_free(expr);
+       ast_free(result);
+
        return res;
 }
 #endif