Skip to content

Commit 3a0f639

Browse files
committed
Check dynamic_cast output before dereferencing in modeler
1 parent a2fcd3b commit 3a0f639

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

apps/modeler/src/cloud_mesh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ pcl::modeler::CloudMesh::updateVtkPoints()
156156
vtk_points_->SetData(vtkSmartPointer<vtkFloatArray>::New());
157157

158158
auto* data = dynamic_cast<vtkFloatArray*>(vtk_points_->GetData());
159+
if (!data)
160+
return;
159161
data->SetNumberOfComponents(3);
160162

161163
// If the dataset has no invalid values, just copy all of them

apps/modeler/src/normals_actor_item.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pcl::modeler::NormalsActorItem::createNormalLines()
6969
points->SetData(vtkSmartPointer<vtkFloatArray>::New());
7070

7171
auto* data = dynamic_cast<vtkFloatArray*>(points->GetData());
72+
if (!data)
73+
return;
7274
data->SetNumberOfComponents(3);
7375

7476
if (cloud->is_dense) {

apps/modeler/src/parameter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ void
8080
pcl::modeler::IntParameter::setEditorData(QWidget* editor)
8181
{
8282
auto* spinBox = dynamic_cast<QSpinBox*>(editor);
83+
if (!spinBox)
84+
return;
8385
spinBox->setAlignment(Qt::AlignHCenter);
8486

8587
int value = int(*this);
@@ -91,6 +93,8 @@ void
9193
pcl::modeler::IntParameter::getEditorData(QWidget* editor)
9294
{
9395
auto* spinBox = dynamic_cast<QSpinBox*>(editor);
96+
if (!spinBox)
97+
return;
9498
int value = spinBox->text().toInt();
9599
current_value_ = value;
96100
}
@@ -126,6 +130,8 @@ void
126130
pcl::modeler::BoolParameter::setEditorData(QWidget* editor)
127131
{
128132
auto* checkBox = dynamic_cast<QCheckBox*>(editor);
133+
if (!checkBox)
134+
return;
129135

130136
bool value = bool(*this);
131137
checkBox->setCheckState(value ? (Qt::Checked) : (Qt::Unchecked));
@@ -136,6 +142,8 @@ void
136142
pcl::modeler::BoolParameter::getEditorData(QWidget* editor)
137143
{
138144
auto* checkBox = dynamic_cast<QCheckBox*>(editor);
145+
if (!checkBox)
146+
return;
139147
bool value = (checkBox->checkState() == Qt::Checked);
140148
current_value_ = value;
141149
}
@@ -175,6 +183,8 @@ void
175183
pcl::modeler::DoubleParameter::setEditorData(QWidget* editor)
176184
{
177185
auto* spinBox = dynamic_cast<QDoubleSpinBox*>(editor);
186+
if (!spinBox)
187+
return;
178188
spinBox->setAlignment(Qt::AlignHCenter);
179189

180190
double value = double(*this);
@@ -186,6 +196,8 @@ void
186196
pcl::modeler::DoubleParameter::getEditorData(QWidget* editor)
187197
{
188198
auto* spinBox = dynamic_cast<QDoubleSpinBox*>(editor);
199+
if (!spinBox)
200+
return;
189201
double value = spinBox->text().toDouble();
190202
current_value_ = value;
191203
}
@@ -221,6 +233,8 @@ void
221233
pcl::modeler::ColorParameter::setEditorData(QWidget* editor)
222234
{
223235
auto* color_dialog = dynamic_cast<QColorDialog*>(editor);
236+
if (!color_dialog)
237+
return;
224238

225239
QColor value = QColor(*this);
226240
color_dialog->setCurrentColor(value);
@@ -231,6 +245,8 @@ void
231245
pcl::modeler::ColorParameter::getEditorData(QWidget* editor)
232246
{
233247
auto* color_dialog = dynamic_cast<QColorDialog*>(editor);
248+
if (!color_dialog)
249+
return;
234250

235251
QColor value = color_dialog->currentColor();
236252
current_value_ = value;

apps/modeler/src/points_actor_item.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ pcl::modeler::PointsActorItem::initImpl()
7878
mapper->InterpolateScalarsBeforeMappingOn();
7979
mapper->ScalarVisibilityOn();
8080

81-
vtkSmartPointer<vtkLODActor> actor =
82-
vtkSmartPointer<vtkLODActor>(dynamic_cast<vtkLODActor*>(actor_.GetPointer()));
81+
auto* actor_ptr = dynamic_cast<vtkLODActor*>(actor_.GetPointer());
82+
if (!actor_ptr)
83+
return;
84+
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>(actor_ptr);
8385
actor->SetMapper(mapper);
8486

8587
actor->SetNumberOfCloudPoints(

apps/modeler/src/surface_actor_item.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ pcl::modeler::SurfaceActorItem::initImpl()
7575
mapper->InterpolateScalarsBeforeMappingOn();
7676
mapper->ScalarVisibilityOn();
7777

78-
vtkSmartPointer<vtkLODActor> actor =
79-
vtkSmartPointer<vtkLODActor>(dynamic_cast<vtkLODActor*>(actor_.GetPointer()));
78+
auto* actor_ptr = dynamic_cast<vtkLODActor*>(actor_.GetPointer());
79+
if (!actor_ptr)
80+
return;
81+
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>(actor_ptr);
8082
actor->SetMapper(mapper);
8183

8284
actor->SetNumberOfCloudPoints(

0 commit comments

Comments
 (0)