-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
to_chars can puts leading zeros on numbers #41511
Comments
Runtime tests for std::to_chars There are currently several failures when using libc++. The first few seem to be the issue described here. There are also some failures in base 2 output, but I didn't analyze them. |
Thanks for your tests.
Yes, I walked through the original code (branchlut3) contributed by RapidJSON author in debugger and saw the same issue. The issue doesn't present in branchlut2. I'm going to contacting him to look at it.
I looked into them, and I think your test cases are asking for something not required by the standard. The standard does not guarantee that we don't modify the space after r.ptr in the buffer. My code may write to anywhere in the buffer provided https://github.com/llvm-mirror/libcxx/blob/master/include/charconv#L377 then move the content to the front if needed. |
Vlad has proposed a fix here: https://reviews.llvm.org/D59178 |
Good catch, I should mark those checks as GNU-specific in our copy, and you won't want to keep that part in the libc++ tests. |
Bugfix proposal: I will be very grateful for a help with review. |
Fixed in revision 362967. |
Extended Description
Given the following code:
#include
#include
#include
template
void test()
{
char buf[100];
auto res = std::to_chars(buf, buf + 100, (T)0xffffffff);
assert(res.ec == std::errc());
*res.ptr = '\0';
std::cout << (const char *) buf << std::endl;
}
int main ()
{
test();
test();
test<int64_t>();
}
I expect this to print:
-1
4294967295
4294967295
4294967295
4294967295
4294967295
but instead it prints:
-1
0004294967295
0004294967295
4294967295
0004294967295
0004294967295
The text was updated successfully, but these errors were encountered: