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

0 is not printed correctly. #3

Closed
syoyo opened this issue Dec 22, 2022 · 2 comments
Closed

0 is not printed correctly. #3

syoyo opened this issue Dec 22, 2022 · 2 comments

Comments

@syoyo
Copy link

syoyo commented Dec 22, 2022

buffer[3] = '\0';

Null character is written at buf[3] for zero.
If we provide uninitialized buffer, buf[1] and buf[2] contains garbage and printf/cout does not work well when we don't use returned the number of string length(e.g. directly construct std::string from char[] buffer)

Possible fix would be

buffer[0] = '0';
buffer[1] = '\0';

?

@aclex
Copy link
Owner

aclex commented Dec 22, 2022

Oh yes, you're certainly right, my bad. That's due to one of the previous changes in 3742c9b. Will fix it now.

Many thanks for your report!

@aclex aclex closed this as completed in 907128a Dec 22, 2022
@syoyo
Copy link
Author

syoyo commented Dec 22, 2022

@aclex Thanks for rapid fix!

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

No branches or pull requests

2 participants