Skip to content
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

Issues with fmt::format_to_n() #1056

Closed
Devenec opened this issue Feb 25, 2019 · 4 comments
Closed

Issues with fmt::format_to_n() #1056

Devenec opened this issue Feb 25, 2019 · 4 comments

Comments

@Devenec
Copy link

Devenec commented Feb 25, 2019

After running the following code

char buffer[32];
const fmt::format_to_n_result<char*> result = fmt::format_to_n(buffer, sizeof(buffer), "{}", 'A');

result.size is 0 when it should be 1.

Also, when changing the format string from "{}" to "{} " (adding a single space), result.size is 1 when it should be 2, and the contents of buffer is " " (a single space) following garbage as it's not null-terminated.

The {fmt} code running is from commit a977577 and built with Visual Studio 2017 15.9.5 v141 toolset.

@abolz
Copy link
Contributor

abolz commented Feb 26, 2019

Seems like the output iterator is not incremented here:

*reserve(1) = value;

Changing this line to

auto&& it = reserve(1); *it++ = value;

fixes the issue, but I haven't run any other tests.

@abolz
Copy link
Contributor

abolz commented Feb 26, 2019

Has been changed in f6fd38b#diff-93ae8f33d84a6b0b08a62dc9a50f6b85L2344

@vitaut
Copy link
Contributor

vitaut commented Feb 26, 2019

@abolz, that's probably it, thanks for investigating. Could you by any chance submit a PR with a small regression test?

@abolz
Copy link
Contributor

abolz commented Feb 26, 2019

Yes, sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants