From 47f4bfea35f5a5a9098b3c7303312ac880160384 Mon Sep 17 00:00:00 2001 From: May Date: Sun, 29 May 2022 22:53:00 -0400 Subject: [PATCH] LibC: Make asctime_r() in time.h POSIX compliant Previously, when the asctime_r() buffer overflowed, we would fail an assertion. This patch modifies asctime_r() to instead set errno and return null. --- Userland/Libraries/LibC/time.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp index 932184fe51..0a66be371a 100644 --- a/Userland/Libraries/LibC/time.cpp +++ b/Userland/Libraries/LibC/time.cpp @@ -208,8 +208,11 @@ char* asctime_r(const struct tm* tm, char* buffer) constexpr size_t assumed_len = 26; size_t filled_size = strftime(buffer, assumed_len, "%a %b %e %T %Y\n", tm); - // Verify that the buffer was large enough. - VERIFY(filled_size != 0); + // If the buffer was not large enough, set EOVERFLOW and return null. + if (filled_size == 0) { + errno = EOVERFLOW; + return nullptr; + } return buffer; }