diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index d7ac7134..f51b12bc 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -2077,8 +2077,8 @@ void QPDFWriter::initializeTables(size_t extra) { auto size = QIntC::to_size(QPDF::Writer::tableSize(m->pdf) + 100) + extra; - m->obj.initialize(size); - m->new_obj.initialize(size); + m->obj.resize(size); + m->new_obj.resize(size); } void diff --git a/libqpdf/qpdf/ObjTable.hh b/libqpdf/qpdf/ObjTable.hh index a1790c55..dd762214 100644 --- a/libqpdf/qpdf/ObjTable.hh +++ b/libqpdf/qpdf/ObjTable.hh @@ -99,15 +99,6 @@ class ObjTable: public std::vector return element(id); } - void - initialize(size_t idx) - { - if (std::vector::size() > 0 || !sparse_elements.empty()) { - throw ::std::logic_error("ObjTable accessed before initialization"); - } - resize(++idx); - } - void resize(size_t a_size) { diff --git a/libtests/obj_table.cc b/libtests/obj_table.cc index 5e83beb6..96ca9fb1 100644 --- a/libtests/obj_table.cc +++ b/libtests/obj_table.cc @@ -10,7 +10,7 @@ class Table: public ObjTable public: Table() { - initialize(5); + resize(5); } void @@ -20,9 +20,19 @@ class Table: public ObjTable (*this)[i].value = 2 * i; (*this)[1000 + i].value = 2 * (1000 + i); } + for (int i: {50, 60, 70, 98, 99, 100, 101, 150, 198, 199, 200, 201}) { + (*this)[i].value = 2 * i; + } + resize(100); + for (int i: {1, 99, 100, 105, 110, 120, 220}) { + (*this)[i].value = 3 * i; + } + resize(200); forEach([](auto i, auto const& item) -> void { - std::cout << std::to_string(i) << " : " << std::to_string(item.value) << "\n"; + if (item.value) { + std::cout << std::to_string(i) << " : " << std::to_string(item.value) << "\n"; + } }); std::cout << "2000 : " << std::to_string((*this)[2000].value) << "\n"; diff --git a/libtests/qtest/obj_table/obj_table.out b/libtests/qtest/obj_table/obj_table.out index 617e3411..6454c26b 100644 --- a/libtests/qtest/obj_table/obj_table.out +++ b/libtests/qtest/obj_table/obj_table.out @@ -1,5 +1,4 @@ -0 : 0 -1 : 2 +1 : 3 2 : 4 3 : 6 4 : 8 @@ -8,6 +7,22 @@ 7 : 14 8 : 16 9 : 18 +50 : 100 +60 : 120 +70 : 140 +98 : 196 +99 : 297 +100 : 300 +101 : 202 +105 : 315 +110 : 330 +120 : 360 +150 : 300 +198 : 396 +199 : 398 +200 : 400 +201 : 402 +220 : 660 1000 : 2000 1001 : 2002 1002 : 2004