Skip to content

format_to_n do not write characters #778

Closed
@ck3d

Description

@ck3d
std::array<char, 1> field{};
assert(fmt::format_to_n(field.begin(), 1, "{}", 'a').size, 1); // passes
assert(field[0] == 'a'); // failes, field[0] == \0

No problems with format_to.

Activity

vitaut

vitaut commented on Jun 10, 2018

@vitaut
Contributor

This works on the latest master:

#include "fmt/format.h"
#include <array>

int main() {
  std::array<char, 1> field{};
  fmt::format_to_n(field.begin(), 1, "{}", 'a');
  fmt::print("{}", field[0]); // prints 'a'
}

Not sure if it is related, but your first assert seems invalid (probably should be == instead of ,).

wkenyon

wkenyon commented on Jun 22, 2018

@wkenyon

This may work on master, but it is broken in the latest release, 5.0.0.
Perhaps it's worth releasing 5.0.1 with this fixed? It seems like a pretty serious bug.

vitaut

vitaut commented on Jun 23, 2018

@vitaut
Contributor

Yes, I plan to release a new minor version soon.

vitaut

vitaut commented on Jul 8, 2018

@vitaut
Contributor

Version 5.1.0 which includes this fix among other things has been released: https://github.com/fmtlib/fmt/releases/tag/5.1.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      format_to_n do not write characters · Issue #778 · fmtlib/fmt