From f68db3d3bee94892a8789363400c8cb3df737e1d Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 4 Oct 2022 12:38:40 +0200 Subject: [PATCH] Fixes after 698c708bf6c15ed63918220e47582d1d937c6e5f --- src/ifcparse/IfcParse.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 4cfd4ae3bd..6b070f2564 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -748,18 +748,21 @@ size_t IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::en } if (vector) { - // @todo figure out whether all this logic is still necessary, since we know the - // expected amount of attributes and shouldn't be able to access more than allowed - // by the schema. - attributes = new Argument*[(std::max)(num_attributes, vector->size())]{ nullptr }; - - // @todo this appears unnecessary, we increment this in the loop already, - // which is more accurate as the filler can't go above it's size in case - // it uses the pre-allocated c-array. - // -> return_value = vector->size(); + // Obviously don't try and create a 0-length array. + if (num_attributes || vector->size()) { + // @todo figure out whether all this logic is still necessary, since we know the + // expected amount of attributes and shouldn't be able to access more than allowed + // by the schema. + attributes = new Argument*[(std::max)(num_attributes, vector->size())]{ nullptr }; - for (size_t i = 0; i < vector->size(); ++i) { - attributes[i] = vector->at(i); + // @todo this appears unnecessary, we increment this in the loop already, + // which is more accurate as the filler can't go above it's size in case + // it uses the pre-allocated c-array. + // -> return_value = vector->size(); + + for (size_t i = 0; i < vector->size(); ++i) { + attributes[i] = vector->at(i); + } } if ((vector != &internal_attribute_vector_) && (vector != &internal_attribute_vector_simple_type_)) {