OSSP CVS Repository

ossp - Difference in ossp-pkg/var/var.c versions 1.41 and 1.42
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/var/var.c 1.41 -> 1.42

--- var.c        2001/12/08 16:17:56     1.41
+++ var.c        2001/12/08 16:27:57     1.42
@@ -97,7 +97,8 @@
         "lookup function does not support variable arrays",                     /* VAR_ERR_ARRAY_LOOKUPS_ARE_UNSUPPORTED = -37 */
         "index specification of array variable contains an invalid character",  /* VAR_ERR_INVALID_CHAR_IN_INDEX_SPEC = -38 */
         "index specification of array variable is incomplete",                  /* VAR_ERR_INCOMPLETE_INDEX_SPEC = -39 */
-        "bracket expression in array variable's index is not closed"            /* VAR_ERR_UNCLOSED_BRACKET_IN_INDEX = -40 */
+        "bracket expression in array variable's index is not closed",           /* VAR_ERR_UNCLOSED_BRACKET_IN_INDEX = -40 */
+        "division by zero error in index specification"                         /* VAR_ERR_DIVISION_BY_ZERO_IN_INDEX = -41 */
     };
 
     rc = 0 - rc;
@@ -547,8 +548,8 @@
             if (rc < 0)
                 return rc;
             p += rc;
-            printf("Expanding variable() failed, eating %d characters and substituting 1.\n", rc);
-            *result = 1;
+            printf("Expanding variable() failed, eating %d characters and substituting 0.\n", rc);
+            *result = 0;
             }
         else
             {
@@ -646,11 +647,33 @@
             p += rc;
             printf("Calculating %d %c %d --> ", *result, operator, right);
             if (operator == '*')
+                {
                 *result = *result * right;
+                }
             else if (operator == '/')
-                *result = *result / right;
+                {
+                if (right == 0)
+                    {
+                    if (*failed)
+                        *result = 0;
+                    else
+                        return VAR_ERR_DIVISION_BY_ZERO_IN_INDEX;
+                    }
+                else
+                    *result = *result / right;
+                }
             else if (operator == '%')
-                *result = *result % right;
+                {
+                if (right == 0)
+                    {
+                    if (*failed)
+                        *result = 0;
+                    else
+                        return VAR_ERR_DIVISION_BY_ZERO_IN_INDEX;
+                    }
+                else
+                    *result = *result % right;
+                }
             printf("%d\n", *result);
             }
         else

CVSTrac 2.0.1