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 06e11d4
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions source/gwb-grid/main.cc
Original file line number Diff line number Diff line change
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 06e11d4

Please sign in to comment.