Skip to content

Commit

Permalink
Merge pull request #3002 from boutproject/gcc-check-nullptr
Browse files Browse the repository at this point in the history
Ensure pointer is checked before dereferencing
  • Loading branch information
bendudson authored Oct 22, 2024
2 parents 09a42a1 + 0280d17 commit 43aa3bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mesh/impls/bout/boutmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,9 @@ int BoutMesh::pack_data(const std::vector<FieldData*>& var_list, int xge, int xl
for (const auto& var : var_list) {
if (var->is3D()) {
// 3D variable
auto& var3d_ref = *dynamic_cast<Field3D*>(var);
auto* var3d_ref_ptr = dynamic_cast<Field3D*>(var);
ASSERT0(var3d_ref_ptr != nullptr);
auto& var3d_ref = *var3d_ref_ptr;
ASSERT2(var3d_ref.isAllocated());
for (int jx = xge; jx != xlt; jx++) {
for (int jy = yge; jy < ylt; jy++) {
Expand All @@ -2307,7 +2309,9 @@ int BoutMesh::pack_data(const std::vector<FieldData*>& var_list, int xge, int xl
}
} else {
// 2D variable
auto& var2d_ref = *dynamic_cast<Field2D*>(var);
auto* var2d_ref_ptr = dynamic_cast<Field2D*>(var);
ASSERT0(var2d_ref_ptr != nullptr);
auto& var2d_ref = *var2d_ref_ptr;
ASSERT2(var2d_ref.isAllocated());
for (int jx = xge; jx != xlt; jx++) {
for (int jy = yge; jy < ylt; jy++, len++) {
Expand Down

0 comments on commit 43aa3bf

Please sign in to comment.