Skip to content

Commit 5a5bdaa

Browse files
authored
Simplify/correct localtime_r.c patch from #10536. NFC (#16103)
I'm hoping we can remove this patch completely if we switch to 64bit time like the reset other targets (I think we we would only do this if we can avoid code size bloat and introducing for 64-bit calls at the wasm->JS boudary).
1 parent a3fa13b commit 5a5bdaa

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

system/lib/libc/musl/src/time/localtime_r.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm)
66
{
7+
/* Unlike other musl targets emscripten uses `int` for time_t rather than
8+
* `int64`, so these checks don't apply (they rightly trigger
9+
* `autological-constant-out-of-range-compare` warnings).
10+
* TODO(sbc): Remove this if/when we switch to using int64 too. */
11+
#ifndef __EMSCRIPTEN__
712
/* Reject time_t values whose year would overflow int because
813
* __secs_to_zone cannot safely handle them. */
9-
// XXX EMSCRIPTEN: add casts to (long long) to avoid a new clang warning
10-
if (((long long)*t) < INT_MIN * 31622400LL || ((long long)*t) > INT_MAX * 31622400LL) {
14+
if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) {
1115
errno = EOVERFLOW;
1216
return 0;
1317
}
18+
#endif
1419
__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
1520
if (__secs_to_tm((long long)*t + tm->__tm_gmtoff, tm) < 0) {
1621
errno = EOVERFLOW;

0 commit comments

Comments
 (0)