+2024-02-10 Paul Eggert <eggert@cs.ucla.edu>
+
+ doc: improve warnings about ctime etc.
+ * doc/posix-functions/asctime.texi (asctime):
+ * doc/posix-functions/asctime_r.texi (asctime_r):
+ Say why these functions are typically used mistakenly.
+ * doc/posix-functions/ctime.texi (ctime):
+ * doc/posix-functions/ctime_r.texi (ctimef):
+ Say that they can dump core due to an internal null pointer, too.
+ * doc/posix-functions/ctime.texi (ctime):
+ Don’t recommend ctime_r.
+
2024-02-10 Bruno Haible <bruno@clisp.org>
havelib: Add support for NetBSD/sparc64.
This function may overflow its internal buffer if its argument
specifies a year before 1000 or after 9999.
@xref{ctime}.
+@item
+Although it is tempting to call this function on the value that
+functions like @code{localtime} return, this is typically a mistake.
+On most current platforms, these functions return a null pointer for
+timestamps out of range, and this function has undefined behavior in
+that case.
@end itemize
This function may overflow its output buffer if its argument
specifies a year before 1000 or after 9999.
@xref{ctime}.
+@item
+Although it is tempting to call this function on the value that
+functions like @code{localtime} return, this is typically a mistake.
+On most current platforms, these functions return a null pointer for
+timestamps out of range, and this function has undefined behavior in
+that case.
@end itemize
This function may overflow its internal buffer if its argument
specifies a time before the year 1000 or after the year 9999.
@item
+This function may dereference an internal null pointer if its argument
+specifies a time before the year @code{INT_MIN}+1900 or after the
+year @code{INT_MAX}+1900.
+@item
The @code{ctime} function need not be reentrant, and consequently is
not required to be thread safe. Implementations of @code{ctime}
typically write the timestamp into static buffer. If two threads
call @code{ctime} at roughly the same time, you might end up with the
-wrong date in one of the threads, or some undefined string. There is
-a reentrant interface @code{ctime_r}.
+wrong date in one of the threads, or some undefined string.
@item
Native Windows platforms (mingw, MSVC) support only a subset of time
zones supported by GNU or specified by POSIX@. @xref{tzset}.
However, today's platforms have a @code{time_t} so wide
that the year might not be in the range [1000, 9999].
In this case the behavior of @code{ctime} is undefined
-and some platforms behave badly, overrunning a buffer;
-and even on platforms where no buffer overrun occurs,
-the 7th Edition code can generate wrong output for out-of-range years,
+and some platforms behave badly, overrunning a buffer
+or dereferencing an internal null pointer;
+and even on platforms where no undefined behavior occurs,
+the 7th Edition code generates wrong output for out-of-range years,
because it incorrectly assumes that every year is represented by
exactly four digits.