Skip to content

Commit

Permalink
fix: avoid accessing arrays of zero size
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristosT committed Jul 1, 2024
1 parent f6fa93d commit a02c1a5
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,30 @@ ParticleTileToBlueprint(const ParticleTile<ParticleType,
} else {
const auto &soa = ptile.GetStructOfArrays();

// for soa entries, we can use standard strides,
// since these are contiguous arrays

// id is the first int entry
conduit::Node &n_f_id = n_fields[topology_name + "_id"];
if(!soa.GetIntData().empty())
{

n_f_id["topology"] = topology_name;
n_f_id["association"] = "element";
n_f_id["values"].set_external(const_cast<int*>(&soa.GetIntData(0)[0]),
num_particles);
// for soa entries, we can use standard strides,
// since these are contiguous arrays

// cpu is the second int entry
conduit::Node &n_f_cpu = n_fields[topology_name + "_cpu"];
// id is the first int entry
conduit::Node &n_f_id = n_fields[topology_name + "_id"];

n_f_cpu["topology"] = topology_name;
n_f_cpu["association"] = "element";
n_f_cpu["values"].set_external(const_cast<int*>(&soa.GetIntData(0)[0]),
num_particles);
n_f_id["topology"] = topology_name;
n_f_id["association"] = "element";
n_f_id["values"].set_external(const_cast<int*>(&soa.GetIntData(0)[0]),
num_particles);

// cpu is the second int entry
conduit::Node &n_f_cpu = n_fields[topology_name + "_cpu"];

n_f_cpu["topology"] = topology_name;
n_f_cpu["association"] = "element";
n_f_cpu["values"].set_external(const_cast<int*>(&soa.GetIntData(0)[0]),
num_particles);

}
}

// --------------------------------
Expand Down Expand Up @@ -389,4 +394,4 @@ ParticleContainerToBlueprint(const ParticleContainer_impl<ParticleType,



}
}

0 comments on commit a02c1a5

Please sign in to comment.