aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-09-18 02:54:32 +0000
committerUlrich Drepper <drepper@redhat.com>2003-09-18 02:54:32 +0000
commitbcc86889c775a0f717de272cc270e3b089aa5221 (patch)
tree163b2cdf47ef949fa9c01eb196974ad98cdd4413 /sysdeps
parent9ba96eda70ecf6f86f74580b23fc387d8fd1cd77 (diff)
downloadglibc-bcc86889c775a0f717de272cc270e3b089aa5221.tar
glibc-bcc86889c775a0f717de272cc270e3b089aa5221.tar.gz
glibc-bcc86889c775a0f717de272cc270e3b089aa5221.tar.bz2
glibc-bcc86889c775a0f717de272cc270e3b089aa5221.zip
Update.
2003-09-17 Ulrich Drepper <drepper@redhat.com> * sysdeps/generic/wordexp.c (eval_expr_val): Use strtol since we have to recognize octal and hexadecimal numbers as well. Simplify function, signs are handled in strtol. * posix/wordexp-test.c: Add tests for octal and hexadecimal numbers in arithmetic expressions.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/wordexp.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/sysdeps/generic/wordexp.c b/sysdeps/generic/wordexp.c
index 46292f07fd..3e37d6449c 100644
--- a/sysdeps/generic/wordexp.c
+++ b/sysdeps/generic/wordexp.c
@@ -554,16 +554,13 @@ static int
internal_function
eval_expr_val (char **expr, long int *result)
{
- int sgn = +1;
char *digit;
/* Skip white space */
for (digit = *expr; digit && *digit && isspace (*digit); ++digit);
- switch (*digit)
+ if (*digit == '(')
{
- case '(':
-
/* Scan for closing paren */
for (++digit; **expr && **expr != ')'; ++(*expr));
@@ -577,27 +574,14 @@ eval_expr_val (char **expr, long int *result)
return WRDE_SYNTAX;
return 0;
-
- case '+': /* Positive value */
- ++digit;
- break;
-
- case '-': /* Negative value */
- ++digit;
- sgn = -1;
- break;
-
- default:
- if (!isdigit (*digit))
- return WRDE_SYNTAX;
}
- *result = 0;
- for (; *digit && isdigit (*digit); ++digit)
- *result = (*result * 10) + (*digit - '0');
+ /* POSIX requires that decimal, octal, and hexadecimal constants are
+ recognized. Therefore we pass 0 as the third parameter to strtol. */
+ *result = strtol (digit, expr, 0);
+ if (digit == *expr)
+ return WRDE_SYNTAX;
- *expr = digit;
- *result *= sgn;
return 0;
}