diff options
author | Elliott Hughes <enh@google.com> | 2020-01-07 08:48:10 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2020-01-07 08:48:10 -0800 |
commit | 5dc31300ff926c7ffdd56f95c080e9b0d6122666 (patch) | |
tree | ad74f1b195684a8afc71b2c1e0e1946db7efd348 /tests/stdio_test.cpp | |
parent | 7bc71075eabaf037397065c0374a536c7eba52e2 (diff) |
Explicitly test printf %s with nullptr.
I haven't found a bug, but tests are good.
Bug: https://github.com/landley/toybox/issues/163
Change-Id: I57149800099abc699cc841b69a5a72aeac7c2bcc
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r-- | tests/stdio_test.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index a0cda1be0..75abbd235 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -853,6 +853,20 @@ TEST(STDIO_TEST, snprintf_asterisk_overflow) { ASSERT_EQ(ENOMEM, errno); } +// Inspired by https://github.com/landley/toybox/issues/163. +TEST(STDIO_TEST, printf_NULL) { + char buf[128]; + char* null = nullptr; + EXPECT_EQ(4, snprintf(buf, sizeof(buf), "<%*.*s>", 2, 2, null)); + EXPECT_STREQ("<(n>", buf); + EXPECT_EQ(8, snprintf(buf, sizeof(buf), "<%*.*s>", 2, 8, null)); + EXPECT_STREQ("<(null)>", buf); + EXPECT_EQ(10, snprintf(buf, sizeof(buf), "<%*.*s>", 8, 2, null)); + EXPECT_STREQ("< (n>", buf); + EXPECT_EQ(10, snprintf(buf, sizeof(buf), "<%*.*s>", 8, 8, null)); + EXPECT_STREQ("< (null)>", buf); +} + TEST(STDIO_TEST, fprintf) { TemporaryFile tf; |