Thanks for reviewing the code; this found a real bug and prompted me to find another. Plus, you found some other things worth sprucing up. To my mind the most important fix in your patch is removing that stray initialization in leapcorr; this fixes a bug in the implementation of the new (2014g) functions time2posix_z and posix2time_z. Christos Zoulas wrote:
There is a bug fix there too; in one of the cases sp->ttis[1] is not initialized, and returns trash to the user.
Sorry, I don't see the bug there; can you explain? I assume you're talking about either the code labeled "only standard time" or the code labeled "so, we're off a little", and in both cases there is only one time type, so the rest of the code should never access sp->ttis[1] and there should be no need to initialize it. Although C99-and-later guarantees that memset(..., 0, ...) sets the struct ttinfo members (which are int, bool, and int_fast32_t) to zero, tzcode assumes only C89 which as I understand it does not provide that guarantee, so to be safe we should avoid memset here. It's easy enough to initialize the remaining structure members by hand. The change to use ssize_t won't fix bugs on modern POSIX platforms, since POSIX nowadays requires int to be at least 32 bits, but the change is probably worth doing for clarity anway, and also to port to ancient POSIX which allowed 16-bit int. However, POSIX weirdly says that ssize_t might not be able to store values less than -1, which means subtracting a value from ssize_t is a no-no if the result might be less than -1, which means we need to redo a subtraction that might compute such a result. Furthermore, the loop from 0 to nread would need an index type other than 'int', but there it's clearer just to use memmove (something that C89 does guarantee). In trying out the code under 'valgrind' I found that the command "zdump ''" tickled some other uninitialized-storage usages: the "so, we're off a little" code doesn't initialize charcnt, goback, goahead, or defaulttype. I hope the attached proposed patch fixes all these problems; please let us know if it misses anything.