summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorMay <mayflowerc10@gmail.com>2022-05-29 22:53:00 -0400
committerLinus Groh <mail@linusgroh.de>2022-06-04 12:23:25 +0100
commit47f4bfea35f5a5a9098b3c7303312ac880160384 (patch)
treea0d096a549588302ad48e76ff1cb48e9c5242741 /Userland/Libraries
parent0ecf17cf91622a82d329b7ea2515a175ef7ce3c3 (diff)
downloadserenity-47f4bfea35f5a5a9098b3c7303312ac880160384.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibC/time.cpp7
1 files 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;
}