diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | posix/wordexp-test.c | 8 | ||||
-rw-r--r-- | sysdeps/generic/wordexp.c | 28 |
3 files changed, 21 insertions, 23 deletions
@@ -1,3 +1,11 @@ +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. + 2003-09-17 Jakub Jelinek <jakub@redhat.com> * elf/Makefile (distribute): Add tst-alignmod.c. diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c index aca9577..db418ce 100644 --- a/posix/wordexp-test.c +++ b/posix/wordexp-test.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1997, 1998, 2000, 2001, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -109,6 +109,11 @@ struct test_case_struct { 0, NULL, "$((-1))", 0, 1, { "-1", }, IFS }, { 0, NULL, "$[50+20]", 0, 1, { "70", }, IFS }, { 0, NULL, "$(((2+3)*(4+5)))", 0, 1, { "45", }, IFS }, + { 0, NULL, "$((010))", 0, 1, { "8" }, IFS }, + { 0, NULL, "$((0x10))", 0, 1, { "16" }, IFS }, + { 0, NULL, "$((010+0x10))", 0, 1, { "24" }, IFS }, + { 0, NULL, "$((-010+0x10))", 0, 1, { "8" }, IFS }, + { 0, NULL, "$((-0x10+010))", 0, 1, { "-8" }, IFS }, /* Advanced parameter expansion */ { 0, NULL, "${var:-bar}", 0, 1, { "bar", }, IFS }, @@ -201,6 +206,7 @@ struct test_case_struct { WRDE_SYNTAX, NULL, "$(for i in)", 0, 0, { NULL, }, IFS }, { WRDE_SYNTAX, NULL, "$((2+))", 0, 0, { NULL, }, IFS }, { WRDE_SYNTAX, NULL, "`", 0, 0, { NULL, }, IFS }, + { WRDE_SYNTAX, NULL, "$((010+4+))", 0, 0, { NULL }, IFS }, { -1, NULL, NULL, 0, 0, { NULL, }, IFS }, }; diff --git a/sysdeps/generic/wordexp.c b/sysdeps/generic/wordexp.c index 46292f0..3e37d64 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; } |