Hi Vincent, On Fri, Aug 23, 2024 at 03:54:49PM GMT, Vincent Lefevre wrote: > On 2024-08-23 15:12:16 +0200, Alejandro Colomar wrote: > > Looking at the WG14 document logs, it seems it was added in n3147: > > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3147.txt> > > Thanks for the reference. Additional details can be found > in CD2 ballot at > > https://open-std.org/JTC1/SC22/WG14/www/docs/n3148.doc It's interesting that WG14 claims that they're not aware of any existing implementations that would modify tm_wday on failure. Although it's weird, because WG14 attributes that claim to the Austin Group, and > > which references the POSIX bug > > https://austingroupbugs.net/view.php?id=1614 I don't see any discussion about tm_wday in that Austin Group bug. :| Maybe it happened in a mailing list or elsewhere. Anyway, let's trust that claim. (If any implementation does not conform, at least it should be feasible to fix that implementation to conform.) > where I can see at the end: > > On page 1332 line 44348 section mktime(), change: > > if (mktime(&time_str) == -1) > > to: > > time_str.tm_wday = -1; > if (mktime(&time_str) == (time_t)-1 && time_str.tm_wday == -1) Yep, they do that change, although I haven't been able to find a discussion that justifies that change. :| (Anyway, I think the change is good. I'm only perplex not finding the justification.) > This is the test I suggested: a check that mktime() returns -1, I think that test suggested by POSIX is bogus (redundant). If mktime(3) has failed, tm_wday is unchanged. If it has succeeded, tm_wday must be changed. Thus, the return value is meaningless for the purpose of determining if it has failed. > and since it can be a valid value, a second test on tm_wday > (where the input, which is ignored, has an invalid value such > as -1 here, or INT_MAX in your case; note that -1 may be more > efficient with some processors, and shorter to write). I didn't use -1 because I thought some weird weeks might contain 8 days (for some of those weird timezone adjustments), and that that might cause wday -1 to actually exist. Thus I chose INT_MIN, which is far far away from valid values, to represent an error. However, I assume that they were careful enough to make sure that such weeks do not exist, so yes, -1 will be better. (And if it's not, we'll blame Austin.) :) Cheers, Alex -- <https://www.alejandro-colomar.es/>
Attachment:
signature.asc
Description: PGP signature