[libc-commits] [libc] [libc] return -1 when v/swprintf truncate output (PR #245838)
via libc-commits
libc-commits at lists.llvm.org
Thu Nov 26 15:42:56 PST 2026
================
@@ -3123,10 +3127,12 @@ TEST_F(LlvmLibcSwprintfTest, CutOff) {
// passing null as the output pointer is allowed as long as bufsz is 0.
written = LIBC_NAMESPACE::swprintf(nullptr, 0, L"%s and more", "1234567890");
- EXPECT_EQ(written, 19);
+ EXPECT_LT(written, 0);
+ ASSERT_ERRNO_FAILURE();
written = LIBC_NAMESPACE::swprintf(nullptr, 0, L"%*s", INT_MIN, "nothing");
- EXPECT_EQ(written, INT_MAX);
+ EXPECT_LT(written, 0);
+ ASSERT_ERRNO_FAILURE();
}
----------------
un-pixelated wrote:
I'd like a test where the output length equals the size of the buffer
Something like
```cpp
written = LIBC_NAMESPACE::swprintf(buff, 5, L"12345");
EXPECT_LT(written, 0);
ASSERT_ERRNO_FAILURE();
```
This is for robustness of the test suite mostly
otherwise overall LGTM 👍
https://github.com/llvm/llvm-project/pull/245838
More information about the libc-commits
mailing list