Skip to content

Commit f447991

Browse files
authored
Don't assume localtime() result is non-nil (apple#280)
Don't assume localtime() result is non-nil
1 parent 86ee8ef commit f447991

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/Logging/Logging.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,9 @@ public struct StreamLogHandler: LogHandler {
13881388
_ = strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", &localTime)
13891389
#else
13901390
var timestamp = time(nil)
1391-
let localTime = localtime(&timestamp)
1391+
guard let localTime = localtime(&timestamp) else {
1392+
return "<unknown>"
1393+
}
13921394
strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
13931395
#endif
13941396
return buffer.withUnsafeBufferPointer {

0 commit comments

Comments
 (0)