Check-in Number:
|
1411 | |
Date: |
2001-Dec-08 17:27:57 (local)
2001-Dec-08 16:27:57 (UTC) |
User: | simons |
Branch: | |
Comment: |
Implemented division-by-zero error. |
Tickets: |
|
Inspections: |
|
Files: |
|
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
|
|
ossp-pkg/var/var.h 1.15 -> 1.16
--- var.h 2001/12/04 13:37:27 1.15
+++ var.h 2001/12/08 16:27:57 1.16
@@ -36,6 +36,7 @@
typedef enum {
VAR_ERR_CALLBACK = -64,
+ VAR_ERR_DIVISION_BY_ZERO_IN_INDEX = -41,
VAR_ERR_UNCLOSED_BRACKET_IN_INDEX = -40,
VAR_ERR_INCOMPLETE_INDEX_SPEC = -39,
VAR_ERR_INVALID_CHAR_IN_INDEX_SPEC = -38,
|
|
ossp-pkg/var/var_test.c 1.20 -> 1.21
--- var_test.c 2001/12/08 16:17:56 1.20
+++ var_test.c 2001/12/08 16:27:57 1.21
@@ -141,7 +141,8 @@
{ "${ARRAY[$NUMBER]}", "entry2" },
{ "${ARRAY[$NUMEXP]}", "entry1" },
{ "${ARRAY[$NUMEXP-1]}", "entry0" },
- { "${ARRAY[${UNDEFINED}-1]}", "${ARRAY[${UNDEFINED}-1]}" }
+ { "${ARRAY[${UNDEFINED}-1]}", "${ARRAY[${UNDEFINED}-1]}" },
+ { "${ARRAY[5/(${UNDEFINED}-1)]}", "${ARRAY[5/(${UNDEFINED}-1)]}" }
};
char *tmp;
size_t tmp_len;
|
|