iconv(3): ignore src_bytes_left if src_bytes is null.
This is undefined behavior, but glibc and macOS are both lenient, and
someone hit this in the wild, so we may as well be lenient too. (The
only cost is that it's now slightly easier to write code that works on
everything except old versions of Android.)
Bug: https://issuetracker.google.com/180598400
Test: treehugger
Change-Id: Ia217169ea6283cc53f4fbf71e5abfa08356c2049
diff --git a/tests/iconv_test.cpp b/tests/iconv_test.cpp
index 768b4fd..bd99000 100644
--- a/tests/iconv_test.cpp
+++ b/tests/iconv_test.cpp
@@ -451,5 +451,13 @@
EXPECT_EQ(0, errno);
EXPECT_EQ(sizeof(out_buf), out_bytes);
+ // Is a null pointer and so is in_bytes. This isn't specified by POSIX, but
+ // glibc and macOS both allow that, where Android historically didn't.
+ // https://issuetracker.google.com/180598400
+ errno = 0;
+ ASSERT_EQ(static_cast<size_t>(0), iconv(c, nullptr, nullptr, &out, &out_bytes));
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(sizeof(out_buf), out_bytes);
+
EXPECT_EQ(0, iconv_close(c));
}