HdfSerializer::read - fix nullptr dereference reading surface styles

The problem was with the line `read_surface_style(surface_styles[i], surface_style_ptrs[i]);` since `surface_style_ptrs[i]` was a nullptr.

Changed the signature to `style&` to make it more clear that it's expecting already created style struct.
This commit is contained in:
Andrej730
2025-08-07 20:24:13 +05:00
parent 67d405ba76
commit 4b7dfcdae5
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -233,8 +233,7 @@ namespace {
} }
} }
void HdfSerializer::read_surface_style(surface_style_serialization& s, const ifcopenshell::geometry::taxonomy::style::ptr& gss_) { void HdfSerializer::read_surface_style(surface_style_serialization& s, ifcopenshell::geometry::taxonomy::style& gss) {
auto& gss = *gss_;
if (strlen(s.name) || s.id) { if (strlen(s.name) || s.id) {
if (s.diffuse[0] == s.diffuse[0]) { if (s.diffuse[0] == s.diffuse[0]) {
gss.diffuse = ifcopenshell::geometry::taxonomy::colour(s.diffuse[0], s.diffuse[1], s.diffuse[2]); gss.diffuse = ifcopenshell::geometry::taxonomy::colour(s.diffuse[0], s.diffuse[1], s.diffuse[2]);
@@ -356,7 +355,7 @@ IfcGeom::Element* HdfSerializer::read(IfcParse::IfcFile& f, const std::string& g
matrix->components() << Eigen::Map<Eigen::Matrix4d>(&part.matrix[0][0]); matrix->components() << Eigen::Map<Eigen::Matrix4d>(&part.matrix[0][0]);
auto style_ptr = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::style>(); auto style_ptr = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::style>();
read_surface_style(part.surface_style, style_ptr); read_surface_style(part.surface_style, *style_ptr);
shapes.push_back(IfcGeom::ConversionResult(part.id, matrix, new ifcopenshell::geometry::OpenCascadeShape(shp), style_ptr)); shapes.push_back(IfcGeom::ConversionResult(part.id, matrix, new ifcopenshell::geometry::OpenCascadeShape(shp), style_ptr));
} }
@@ -421,7 +420,8 @@ IfcGeom::Element* HdfSerializer::read(IfcParse::IfcFile& f, const std::string& g
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> surface_style_ptrs(surface_styles.size()); std::vector<ifcopenshell::geometry::taxonomy::style::ptr> surface_style_ptrs(surface_styles.size());
for (size_t i = 0; i < surface_styles.size(); ++i) { for (size_t i = 0; i < surface_styles.size(); ++i) {
read_surface_style(surface_styles[i], surface_style_ptrs[i]); surface_style_ptrs[i] = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::style>();
read_surface_style(surface_styles[i], *surface_style_ptrs[i]);
} }
triangulation_geometry = boost::shared_ptr<IfcGeom::Representation::Triangulation>(new IfcGeom::Representation::Triangulation( triangulation_geometry = boost::shared_ptr<IfcGeom::Representation::Triangulation>(new IfcGeom::Representation::Triangulation(
+1 -1
View File
@@ -90,7 +90,7 @@ private:
std::map<std::string, std::string> group_cache_; std::map<std::string, std::string> group_cache_;
H5::Group createRepresentationGroup(const H5::Group& element_group, const std::string& gid); H5::Group createRepresentationGroup(const H5::Group& element_group, const std::string& gid);
void read_surface_style(surface_style_serialization& sss, const ifcopenshell::geometry::taxonomy::style::ptr& style_ptr); void read_surface_style(surface_style_serialization& serialized_style, ifcopenshell::geometry::taxonomy::style& style);
void write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style::ptr& s); void write_style(surface_style_serialization& data, const ifcopenshell::geometry::taxonomy::style::ptr& s);
public: public: