
28 Nov
2024
28 Nov
'24
2:05 p.m.
* asctime.c (asctime_r): Don’t assume strcpy preserves errno. Although POSIX.1-2024 requires it, earlier versions of POSIX did not. --- asctime.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/asctime.c b/asctime.c index 7bc19fd1..51ce5a50 100644 --- a/asctime.c +++ b/asctime.c @@ -80,8 +80,11 @@ asctime_r(struct tm const *restrict timeptr, char *restrict buf) #endif if (timeptr == NULL) { + strcpy(buf, "??? ??? ?? ??:??:?? ????\n"); + /* Set errno now, since strcpy might change it in + POSIX.1-2017 and earlier. */ errno = EINVAL; - return strcpy(buf, "??? ??? ?? ??:??:?? ????\n"); + return buf; } if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) wn = "???"; -- 2.43.0