From df808f0ed3c722d245dbb130b270453cfdda6ff2 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Tue, 20 Apr 2021 16:26:12 -0700 Subject: [PATCH] LibC: Fix missing '\n' at the end of ctime/ctime_r/asctime/asctime_r @linusg noticed this bug in the original implementation during code review. This makes all of these API's more spec conforming. --- Userland/Libraries/LibC/time.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp index 966521d994..895d2806df 100644 --- a/Userland/Libraries/LibC/time.cpp +++ b/Userland/Libraries/LibC/time.cpp @@ -193,7 +193,11 @@ char* asctime_r(const struct tm* tm, char* buffer) { // Spec states buffer must be at least 26 bytes. constexpr size_t assumed_len = 26; - strftime(buffer, assumed_len, "%a %b %e %T %Y", tm); + 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); + return buffer; }