This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Ensure mktime sets errno on error (bug 23789)


On Thu, Oct 25, 2018 at 8:59 AM Albert ARIBAUD <albert.aribaud@3adev.fr> wrote:
> >
> > This patch is not correct since -1 is a valid time_t value, and a result of -1
> > does not necessarily indicate time_t overflow.
>
> While a do agree that -1 is a valid time_t value in general terms, in
> the specific case of the mktime() return values, -1 is the value
> returned on error

Yes, but it is *also* a value that can be returned as the result of a
*successful* call to mktime.  Specifically, I believe this program is
required to print

    tv=-1 errno=0

on a system conforming to POSIX, when invoked with the time zone set to UTC:

#include <stdio.h>
#include <time.h>
#include <errno.h>

int main(void)
{
  struct tm tm;
  tm.tm_sec   = 59;
  tm.tm_min   = 59;
  tm.tm_hour  = 23;
  tm.tm_mday  = 31;
  tm.tm_mon   = 11;
  tm.tm_year  = 69;
  tm.tm_wday  = 0;
  tm.tm_yday  = 0;
  tm.tm_isdst = 0;

  errno = 0;
  time_t tv = mktime(&tm);
  int err = errno;

  printf("tv=%lld errno=%d\n", (long long)tv, err);
  return 0;
}

This is similar to how strtol can return LONG_MAX either because the
input string was exactly the decimal representation of LONG_MAX, or
because the input string was the representation of a number too large
for "long"; errno is required *not* to be set to ERANGE in the first
case.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]