From ad69dcb335353bf75357f385dab62ad109fa7b96 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 8 Mar 2016 11:35:22 +0800 Subject: [PATCH] need to copy worksheet_ipml before modifying worksheet container, otherwise handle become invalid during realloc --- source/workbook/tests/test_workbook.hpp | 2 +- source/workbook/workbook.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 878475c4..6d354b93 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -39,7 +39,7 @@ public: xlnt::workbook wb; auto new_sheet = wb.create_sheet(); wb.add_sheet(new_sheet); - TS_ASSERT(new_sheet.compare(wb[2], false)); + TS_ASSERT(wb[1].compare(wb[2], false)); } // void test_add_sheetname() {} unnecessary diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index b333e56b..da01e810 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -160,7 +160,9 @@ worksheet workbook::create_sheet() void workbook::add_sheet(xlnt::worksheet worksheet) { if(worksheet.d_->parent_ != this) throw xlnt::value_error(); - d_->worksheets_.emplace_back(*worksheet.d_); + + xlnt::detail::worksheet_impl impl(*worksheet.d_); + *create_sheet().d_ = impl; } void workbook::add_sheet(xlnt::worksheet worksheet, std::size_t index)