Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: segfault in strftime



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