[tz] why does mktime binary search?

Russ Allbery eagle at eyrie.org
Fri Jul 29 20:54:28 UTC 2016

enh via tz <tz at iana.org> writes:

> this came up on Android because we had some code that did "errno = 0;
> mktime(...); if (errno == EOVERFLOW) ..." rather than checking the
> return value of mktime. this failed for us because the tzcode mktime
> sets errno even on non-failure.

Separate from the question of whether binary search is a good idea...

This is, in general, an error in C programming unless the C API
specifically documents this error checking pattern (strtol is one of the
few APIs that does).  If you call a library function that is documented as
setting errno, and it does not return an error, errno is undefined.  glibc
sets errno to various things on non-failure in many of its interfaces, so
code that assumes errno will only be non-zero on failure is going to break
a lot.

Russ Allbery (eagle at eyrie.org)              <http://www.eyrie.org/~eagle/>

More information about the tz mailing list