From 8cf30aa2be256eba07bb1cefb998c52326e846e7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 1 Feb 2018 21:28:20 -0800 Subject: [PATCH] Fix segfault on complex pointer formatting (#642) --- fmt/format.h | 6 +++--- test/format-test.cc | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fmt/format.h b/fmt/format.h index 23276591..6a8fa66b 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -3000,13 +3000,13 @@ typename BasicWriter::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) { diff --git a/test/format-test.cc b/test/format-test.cc index c836541e..ec232e82 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1761,3 +1761,7 @@ void convert(int); TEST(FormatTest, ConvertCollision) { fmt::format("{}", 42); } + +TEST(FormatTest, Regression) { + fmt::format("...........{:<77777.7p}", "foo"); +}