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

MemoryWriter allocation issue #491

Closed
meox opened this issue Apr 3, 2017 · 1 comment
Closed

MemoryWriter allocation issue #491

meox opened this issue Apr 3, 2017 · 1 comment

Comments

@meox
Copy link

meox commented Apr 3, 2017

I wrote this test case, but it fails:

TEST(OStreamTest, MemoryWriterAllocation) {
  fmt::MemoryWriter w;
  size_t final_len{};
  const size_t l = 10000;

  for (size_t i = 0; i < l; i++) {
    const std::string token = std::to_string(i);
    final_len += token.size();
    w << token;
  }

  const std::string rs = w.str();
  EXPECT_EQ(w.size(), final_len);
}

I'm getting this stack trace:

ostream-test: malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff7027067 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56      ../nptl/sysdeps/unix/sysv/linux/raise.c: File o directory non esistente.
(gdb) bt
#0  0x00007ffff7027067 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff7028448 in __GI_abort () at abort.c:89
#2  0x00007ffff706a0ad in __malloc_assert (
    assertion=assertion@entry=0x7ffff715a748 "(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offs"..., file=file@entry=0x7ffff715628d "malloc.c", line=line@entry=2372, 
    function=function@entry=0x7ffff715660b <__func__.11291> "sysmalloc") at malloc.c:293
#3  0x00007ffff706cd90 in sysmalloc (av=0x7ffff7397620 <main_arena>, nb=19232) at malloc.c:2369
#4  _int_malloc (av=0x7ffff7397620 <main_arena>, bytes=19210) at malloc.c:3800
#5  0x00007ffff706e020 in __GI___libc_malloc (bytes=19210) at malloc.c:2891
#6  0x00007ffff79132e8 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x000000000049c5c0 in __gnu_cxx::new_allocator<char>::allocate (this=0x7fffffffd950, __n=19210) at /usr/include/c++/4.9/ext/new_allocator.h:104
#8  0x00000000004a3298 in fmt::internal::MemoryBuffer<char, 500ul, std::allocator<char> >::grow (this=0x7fffffffd950, size=12810) at /home/meox/git/fmt/fmt/format.h:807
#9  0x000000000048e4f8 in fmt::Buffer<char>::resize (this=0x7fffffffd950, new_size=12810) at /home/meox/git/fmt/fmt/format.h:702
#10 0x000000000048c23d in fmt::operator<< <std::string, char> (writer=..., value="3479") at /home/meox/git/fmt/fmt/ostream.h:138
#11 0x000000000048711c in OStreamTest_MemoryWriterAllocation_Test::TestBody (this=0x71e240) at /home/meox/git/fmt/test/ostream-test.cc:203
#12 0x00000000004cf88e in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=0x71e240, method=&virtual testing::Test::TestBody(), 
    location=0x4e9263 "the test body") at /home/meox/git/fmt/test/gmock-gtest-all.cc:3562
#13 0x00000000004c9c24 in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x71e240, method=&virtual testing::Test::TestBody(), 
    location=0x4e9263 "the test body") at /home/meox/git/fmt/test/gmock-gtest-all.cc:3598
#14 0x00000000004aacff in testing::Test::Run (this=0x71e240) at /home/meox/git/fmt/test/gmock-gtest-all.cc:3635
#15 0x00000000004ab46f in testing::TestInfo::Run (this=0x71e150) at /home/meox/git/fmt/test/gmock-gtest-all.cc:3810
#16 0x00000000004aba78 in testing::TestCase::Run (this=0x71d490) at /home/meox/git/fmt/test/gmock-gtest-all.cc:3928
#17 0x00000000004b2119 in testing::internal::UnitTestImpl::RunAllTests (this=0x71d150) at /home/meox/git/fmt/test/gmock-gtest-all.cc:5799
#18 0x00000000004d06cd in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x71d150, 
    method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x4b1e96 <testing::internal::UnitTestImpl::RunAllTests()>, 
    location=0x4e9b40 "auxiliary test code (environments or event listeners)") at /home/meox/git/fmt/test/gmock-gtest-all.cc:3562
#19 0x00000000004ca9be in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x71d150, 
    method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x4b1e96 <testing::internal::UnitTestImpl::RunAllTests()>, 
    location=0x4e9b40 "auxiliary test code (environments or event listeners)") at /home/meox/git/fmt/test/gmock-gtest-all.cc:3598
#20 0x00000000004b0eab in testing::UnitTest::Run (this=0x71cc00 <testing::UnitTest::GetInstance()::instance>) at /home/meox/git/fmt/test/gmock-gtest-all.cc:5413
#21 0x00000000004a570d in RUN_ALL_TESTS () at /home/meox/git/fmt/test/./gtest/gtest.h:20062
#22 0x00000000004a5694 in main (argc=1, argv=0x7fffffffe058) at /home/meox/git/fmt/test/test-main.cc:57
@effzeh
Copy link
Contributor

effzeh commented Apr 4, 2017

Same here with MinGW 6.3 on Windows.

This seems to be a bug in the FormatBuf implementation in ostream.h. operator<< defined here in ostream.h is quite greedy and gets picked up for a (const) std::string.

I'm quite sure that this is incorrect: it sets the end pointer past the buffer when invoked here with size() > 0. But I don't have the time right now to investigate that further.

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