Skip to content

Commit

Permalink
Fix segfault on complex pointer formatting (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Feb 2, 2018
1 parent 0555cea commit 8cf30aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3000,13 +3000,13 @@ typename BasicWriter<Char>::CharPtr
CharPtr p = grow_buffer(fill_size);
std::uninitialized_fill(p, p + fill_size, fill);
}
CharPtr result = prepare_int_buffer(
num_digits, subspec, prefix, prefix_size);
std::ptrdiff_t offset = get(prepare_int_buffer(
num_digits, subspec, prefix, prefix_size)) - &buffer_[0];
if (align == ALIGN_LEFT) {
CharPtr p = grow_buffer(fill_size);
std::uninitialized_fill(p, p + fill_size, fill);
}
return result;
return internal::make_ptr(&buffer_[0], buffer_.size()) + offset;
}
unsigned size = prefix_size + num_digits;
if (width <= size) {
Expand Down
4 changes: 4 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1761,3 +1761,7 @@ void convert(int);
TEST(FormatTest, ConvertCollision) {
fmt::format("{}", 42);
}

TEST(FormatTest, Regression) {
fmt::format("...........{:<77777.7p}", "foo");
}

0 comments on commit 8cf30aa

Please sign in to comment.