[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test -t
From: |
Paul Jarc |
Subject: |
Re: test -t |
Date: |
Sun, 07 Sep 2008 15:31:40 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Chet Ramey <chet.ramey@case.edu> wrote:
> jidanni@jidanni.org wrote:
>> Is this a bug?
>>
>>>> $ t=test #bash builtin
>>>> $ $t -t ' '; echo $?
>>>> 0
>
> Doesn't look like it:
I think it is a bug, but libc may or may not hide it, depending on the
strtol[l] implementation. SUS says:
# If the subject sequence is empty or does not have the expected form,
# no conversion is performed; the value of str is stored in the object
# pointed to by endptr, provided that endptr is not a null pointer.
...
# If no conversion could be performed, 0 shall be returned and errno may
# be set to [EINVAL].
Note it says "errno may be set", not "shall". bash seems to assume
"shall" in legal_number() in general.c:
errno = 0;
value = strtoimax (string, &ep, 10);
if (errno)
return 0; /* errno is set on overflow or underflow */
I think the test should be:
if (errno || ep == string)
This should be reliable, according to SUS:
# If the subject sequence is empty or does not have the expected form,
# no conversion is performed; the value of str is stored in the object
# pointed to by endptr, provided that endptr is not a null pointer.
paul