1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:27:36 +00:00

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.
This commit is contained in:
May 2022-05-29 22:53:00 -04:00 committed by Linus Groh
parent 0ecf17cf91
commit 47f4bfea35

View file

@ -208,8 +208,11 @@ char* asctime_r(const struct tm* tm, char* buffer)
constexpr size_t assumed_len = 26; constexpr size_t assumed_len = 26;
size_t filled_size = strftime(buffer, assumed_len, "%a %b %e %T %Y\n", tm); size_t filled_size = strftime(buffer, assumed_len, "%a %b %e %T %Y\n", tm);
// Verify that the buffer was large enough. // If the buffer was not large enough, set EOVERFLOW and return null.
VERIFY(filled_size != 0); if (filled_size == 0) {
errno = EOVERFLOW;
return nullptr;
}
return buffer; return buffer;
} }