Skip to content

Commit

Permalink
Prevent integer overflow for large grid files
Browse files Browse the repository at this point in the history
  • Loading branch information
gassmoeller committed Mar 25, 2024
1 parent e8aa93d commit ace0015
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions source/gwb-grid/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ int main(int argc, char **argv)
grid_y.resize(n_p);
grid_z.resize(n_p);
grid_depth.resize(n_p);
grid_connectivity.resize(n_cell,std::vector<size_t>(n_v));
grid_connectivity.resize(n_cell,std::vector<vtu11::VtkIndexType>(n_v));


for (size_t i = 0; i < n_cell_z + 1; ++i)
Expand Down Expand Up @@ -1519,33 +1519,33 @@ int main(int argc, char **argv)
if (dim == 2)
for (size_t i = 0; i < n_cell; ++i)
{
connectivity[i*pow_2_dim] = static_cast<int>(grid_connectivity[i][0]);
connectivity[i*pow_2_dim+1] = static_cast<int>(grid_connectivity[i][1]);
connectivity[i*pow_2_dim+2] = static_cast<int>(grid_connectivity[i][2]);
connectivity[i*pow_2_dim+3] = static_cast<int>(grid_connectivity[i][3]);
connectivity[i*pow_2_dim] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][0]);
connectivity[i*pow_2_dim+1] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][1]);
connectivity[i*pow_2_dim+2] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][2]);
connectivity[i*pow_2_dim+3] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][3]);
}
else
for (size_t i = 0; i < n_cell; ++i)
{

connectivity[i*pow_2_dim] = static_cast<int>(grid_connectivity[i][0]);
connectivity[i*pow_2_dim+1] = static_cast<int>(grid_connectivity[i][1]);
connectivity[i*pow_2_dim+2] = static_cast<int>(grid_connectivity[i][2]);
connectivity[i*pow_2_dim+3] = static_cast<int>(grid_connectivity[i][3]);
connectivity[i*pow_2_dim+4] = static_cast<int>(grid_connectivity[i][4]);
connectivity[i*pow_2_dim+5] = static_cast<int>(grid_connectivity[i][5]);
connectivity[i*pow_2_dim+6] = static_cast<int>(grid_connectivity[i][6]);
connectivity[i*pow_2_dim+7] = static_cast<int>(grid_connectivity[i][7]);
connectivity[i*pow_2_dim] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][0]);
connectivity[i*pow_2_dim+1] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][1]);
connectivity[i*pow_2_dim+2] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][2]);
connectivity[i*pow_2_dim+3] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][3]);
connectivity[i*pow_2_dim+4] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][4]);
connectivity[i*pow_2_dim+5] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][5]);
connectivity[i*pow_2_dim+6] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][6]);
connectivity[i*pow_2_dim+7] = static_cast<vtu11::VtkIndexType>(grid_connectivity[i][7]);
}
std::cout << "[5/6] Preparing to write the paraview file: stage 3 of 6, creating the offsets \r";
std::cout.flush();
std::vector<vtu11::VtkIndexType> offsets(n_cell);
if (dim == 2)
for (size_t i = 0; i < n_cell; ++i)
offsets[i] = static_cast<int>((i+1) * 4);
offsets[i] = static_cast<vtu11::VtkIndexType>((i+1) * 4);
else
for (size_t i = 0; i < n_cell; ++i)
offsets[i] = static_cast<int>((i+1) * 8);
offsets[i] = static_cast<vtu11::VtkIndexType>((i+1) * 8);

std::cout << "[5/6] Preparing to write the paraview file: stage 4 of 6, creating the Data set info \r";
std::cout.flush();
Expand Down

0 comments on commit ace0015

Please sign in to comment.