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

fmt::ostream move constructor does not properly initialize buffer #1844

Closed
Boostibot opened this issue Aug 31, 2020 · 2 comments
Closed

fmt::ostream move constructor does not properly initialize buffer #1844

Boostibot opened this issue Aug 31, 2020 · 2 comments

Comments

@Boostibot
Copy link

The following code causes a segmentation fault:

fmt::ostream temp_file = fmt::output_file("file.txt");
fmt::ostream move_constructed(std::move(temp_file));
move_constructed.print("Hello world"); //SIGSEGV - Segmentation fault

This is because the internal buffer pointer and data is left uninitialised and left pointing to null.

The following change to fmt::ostream::ostream(ostream&& ) solves this issue

ostream(ostream&& other) : file_(std::move(other.file_)) {
    set(other.data(), other.capacity()); //Added - Initialises the data
    other.set(nullptr, 0);
  }
@vitaut
Copy link
Contributor

vitaut commented Aug 31, 2020

Could you submit a PR?

@vitaut
Copy link
Contributor

vitaut commented Sep 1, 2020

Fixed in 6cccdc2. Thanks for catching this.

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