diff options
Diffstat (limited to 'libc/test/src/time/strftime_test.cpp')
| -rw-r--r-- | libc/test/src/time/strftime_test.cpp | 21 | 
1 files changed, 21 insertions, 0 deletions
| diff --git a/libc/test/src/time/strftime_test.cpp b/libc/test/src/time/strftime_test.cpp index cac7560..52221527 100644 --- a/libc/test/src/time/strftime_test.cpp +++ b/libc/test/src/time/strftime_test.cpp @@ -2326,3 +2326,24 @@ TEST(LlvmLibcStrftimeTest, TimeFormatFullDateTime) {  //    size_t written = 0;  //    SimplePaddedNum spn;  //  } + +TEST(LlvmLibcStrftimeTest, BufferTooSmall) { +  struct tm time; +  char tiny_buffer[1]; + +  time.tm_year = get_adjusted_year(2025); +  time.tm_mon = 10; +  time.tm_mday = 24; + +  size_t written = +      LIBC_NAMESPACE::strftime(tiny_buffer, sizeof(tiny_buffer), "%F", &time); +  EXPECT_EQ(written, size_t{0}); + +  char small_buffer[10]; + +  // The string "2025-11-24" is 10 chars, +  // so strftime needs 10 + 1 bytes to write the string and the null terminator. +  written = +      LIBC_NAMESPACE::strftime(small_buffer, sizeof(small_buffer), "%F", &time); +  EXPECT_EQ(written, size_t{0}); +} | 
