Vincent Lefevre wrote in <20211022104139.gb2...@cventin.lip.ens-lyon.fr>: |About the following commit:
(I have not seen this commit.) |commit 60ab5f117d813b6ea7bdd6dacc1a771ea63edc6d |Author: Kevin McCarthy <ke...@8t8.us> |Date: 2021-10-20 03:48:47 +0200 | | Add internal mutt_ctime() implementation. | | ctime() is marked obsolescent in the POSIX guide, so we ought to stop | using it to ensure future portability. | |ctime() may be marked obsolescent in the POSIX guide, but it is still |specified by ISO C, and AFAIK, not marked obsolescent there, even in |the latest C2x draft N2176. | |Moreover, ISO C says: "It is equivalent to | | asctime(localtime(timer))" | |So, if you want to replace ctime(), why no using just that? |... unless there is an issue with asctime(), in which case ctime() |would be affected as a consequence. Wasn't this already here?? I want to point to the busybox documentation as quoted, and note i *saw* that crash. Don't mind the format please, this is old code. Ciao. char * n_time_ctime(s64 secsepoch, struct tm const *localtime_or_nil){/* TODO err*/ /* Problem is that secsepoch may be invalid for representation of ctime(3), * which indeed is asctime(localtime(t)); musl libc says for asctime(3): * ISO C requires us to use the above format string, * even if it will not fit in the buffer. Thus asctime_r * is _supposed_ to crash if the fields in tm are too large. * We follow this behavior and crash "gracefully" to warn * application developers that they may not be so lucky * on other implementations (e.g. stack smashing..). * So we need to do it on our own or the libc may kill us */ static char buf[32]; /* TODO static buffer (-> datetime_to_format()) */ s32 y, md, th, tm, ts; char const *wdn, *mn; struct tm const *tmp; NYD_IN; LCTA(FIELD_SIZEOF(struct time_current,tc_ctime) == sizeof(buf), "Buffers should have equal size"); if((tmp = localtime_or_nil) == NIL){ time_t t; t = (time_t)secsepoch; jredo: if((tmp = localtime(&t)) == NIL){ /* TODO error log */ t = 0; goto jredo; } } if(UNLIKELY((y = tmp->tm_year) < 0 || y >= 9999/*S32_MAX*/ - 1900)){ y = 1970; wdn = su_time_weekday_names_abbrev[su_TIME_WEEKDAY_THURSDAY]; mn = su_time_month_names_abbrev[su_TIME_MONTH_JANUARY]; md = 1; th = tm = ts = 0; }else{ y += 1900; wdn = su_TIME_WEEKDAY_IS_VALID(tmp->tm_wday) ? su_time_weekday_names_abbrev[tmp->tm_wday] : n_qm; mn = su_TIME_MONTH_IS_VALID(tmp->tm_mon) ? su_time_month_names_abbrev[tmp->tm_mon] : n_qm; if((md = tmp->tm_mday) < 1 || md > 31) md = 1; if((th = tmp->tm_hour) < 0 || th > 23) th = 0; if((tm = tmp->tm_min) < 0 || tm > 59) tm = 0; if((ts = tmp->tm_sec) < 0 || ts > 60) ts = 0; } (void)snprintf(buf, sizeof buf, "%3s %3s%3d %.2d:%.2d:%.2d %d", wdn, mn, md, th, tm, ts, y); NYD_OU; return buf; } --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)