Skip to content

Commit dc0d533

Browse files
committed
Initialize all MeshBlock member variables
This prevents undefined behavior from uninitialized variables
1 parent 1f0205c commit dc0d533

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/mesh/meshblock.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ class MeshBlock : public std::enable_shared_from_this<MeshBlock> {
150150
//
151151
IndexShape c_cellbounds;
152152
IndexShape f_cellbounds;
153-
int gid, lid;
154-
int cnghost;
155-
int gflag;
153+
int gid = -1;
154+
int lid = -1;
155+
int cnghost = 0;
156+
int gflag = 0;
156157

157158
const IndexShape &GetCellBounds(CellLevel cl) const {
158159
if (cl == CellLevel::same) {
@@ -454,7 +455,9 @@ class MeshBlock : public std::enable_shared_from_this<MeshBlock> {
454455

455456
private:
456457
// data
457-
Real new_block_dt_, new_block_dt_hyperbolic_, new_block_dt_parabolic_;
458+
Real new_block_dt_ = 0.0;
459+
Real new_block_dt_hyperbolic_ = 0.0;
460+
Real new_block_dt_parabolic_ = 0.0;
458461
std::vector<std::shared_ptr<Variable<Real>>> vars_cc_;
459462

460463
// Initializer to set up a meshblock called with the default constructor
@@ -481,15 +484,15 @@ class MeshBlock : public std::enable_shared_from_this<MeshBlock> {
481484

482485
// functions and variables for automatic load balancing based on timing
483486
Kokkos::Timer lb_timer;
484-
double cost_;
487+
double cost_ = 1.0;
485488
// JMM: these are private since the timing machinery only works
486489
// per-meshblock nopt per-meshdata.
487490
void ResetTimeMeasurement();
488491
void StartTimeMeasurement();
489492
void StopTimeMeasurement();
490493

491494
// memory usage on a block
492-
std::uint64_t mem_usage_;
495+
std::uint64_t mem_usage_ = 0;
493496

494497
// Block connectivity information - private to enforce modification only through
495498
// SetMeshBlockNeighbors

0 commit comments

Comments
 (0)