Skip to content

Commit 16a5f7e

Browse files
[libc] Fix implict cast to time_t warning (llvm#126947)
On some systems time_t is 32 bit, causing build errors (with -Werror) in get_epoch which attempts to implicitly convert an int64_t to a time_t. Fixes: error: implicit conversion loses integer precision: 'int64_t' (aka 'long long') to 'time_t' (aka 'int') [-Werror,-Wshorten-64-to-32] 332 | return mktime_internal(timeptr); | ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
1 parent c665480 commit 16a5f7e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libc/src/time/time_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ class TMReader final {
328328
return BASE_YEAR + IS_NEXT_YEAR;
329329
}
330330

331-
LIBC_INLINE time_t get_epoch() const { return mktime_internal(timeptr); }
331+
LIBC_INLINE time_t get_epoch() const {
332+
return static_cast<time_t>(mktime_internal(timeptr));
333+
}
332334

333335
// returns the timezone offset in microwave time:
334336
// return (hours * 100) + minutes;

0 commit comments

Comments
 (0)