-
Notifications
You must be signed in to change notification settings - Fork 116
verifies issue 911 #913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verifies issue 911 #913
Conversation
| char output[2]; | ||
| size_t written = simdutf::convert_utf16_to_utf8_safe( | ||
| input, 2, output, 2); | ||
| ASSERT_EQUAL(written, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this verify written<=2 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pauldreik Hmmm... The first character in the input is é which should be converted to TWO bytes in UTF-8. No?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I was thinking we are just verifying the promise of not writing past the output length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind. Changing it.
|
I made a constexpr test for this, which also catches it: namespace {
template <auto input, std::size_t buflen>
constexpr auto convert_insufficient_buf() {
using namespace simdutf::tests::helpers;
constexpr auto Noutput = simdutf::utf8_length_from_utf16(input);
CTString<char8_t, buflen> output{};
const auto ret = simdutf::convert_utf16_to_utf8_safe(input, output);
if (ret == 0) {
throw "failed conversion";
}
return output;
}
} // namespace
TEST(compile_time_check_of_issue_911) {
using namespace simdutf::tests::helpers;
constexpr auto input = u"\u00E9A"_utf16;
constexpr auto expected = u8"\u00E9A"_utf8;
constexpr auto actual = convert_insufficient_buf<input, 2>();
constexpr auto N = std::min(actual.size(), expected.size());
static_assert(expected.shrink<N>() == actual.shrink<N>());
} |
Adding it. |
|
@pauldreik Have another look. |
See #911