Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: segfault in strftime
- X-seq: zsh-users 14899
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: segfault in strftime
- Date: Fri, 26 Feb 2010 16:07:49 +0100
- In-reply-to: <20100226125256.GC13766@xxxxxxxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <A73C7D9C-66C5-4BFA-8FB3-8560FE65B529@xxxxxxxxxxx> <20100226125256.GC13766@xxxxxxxxxxxxxxxxxxx>
On 2010-02-26 13:52:56 +0100, Vincent Lefevre wrote:
> Also, it seems to have a problem with -1:
>
> Under Mac OS X:
>
> $ strftime "%a %d.%m.%Y %H:%M:%S" -2
> Thu 01.01.1970 00:59:58
> $ strftime "%a %d.%m.%Y %H:%M:%S" -1
> strftime: -1: unknown error: 0
>
> Under Linux/x86_64 (Debian/unstable):
>
> $ strftime "%a %d.%m.%Y %H:%M:%S" -2
> Thu 01.01.1970 00:59:58
> $ strftime "%a %d.%m.%Y %H:%M:%S" -1
> strftime: -1: success
Concerning this one:
secs = (time_t)strtoul(argv[1], &endptr, 10);
if (secs == (time_t)ULONG_MAX) {
zwarnnam(nam, "%s: %e", argv[1], errno);
return 1;
} else if (*endptr != '\0') {
zwarnnam(nam, "%s: invalid decimal number", argv[1]);
return 1;
}
ULONG_MAX is not necessarily an error! You need to check errno.
The C99 standard says:
The strtol, strtoll, strtoul, and strtoull functions return the
converted value, if any. If no conversion could be performed, zero
is returned. If the correct value is outside the range of
representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,
ULONG_MAX, or ULLONG_MAX is returned (according to the return type
and sign of the value, if any), and the value of the macro ERANGE
is stored in errno.
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author