From b26fdd0720eb0a4c89213f3ad757811746d4564c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 17 Mar 2008 05:39:51 +0000 Subject: [PATCH] Avoid accessing elements of vectors beyond the end even if the result is not used, since this trips up debug versions of the STL. git-svn-id: https://svn.dealii.org/trunk@15900 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/source/grid/grid_generator.cc | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/deal.II/deal.II/source/grid/grid_generator.cc b/deal.II/deal.II/source/grid/grid_generator.cc index f365c61c9d..dae12f9c85 100644 --- a/deal.II/deal.II/source/grid/grid_generator.cc +++ b/deal.II/deal.II/source/grid/grid_generator.cc @@ -591,9 +591,18 @@ subdivided_hyper_rectangle(Triangulation &tria, case 1: { double x=0; - for (unsigned int i=0; i<=step_sizes[0].size(); ++i) + for (unsigned int i=0; ; ++i) { points.push_back (Point (p1[0]+x)); + + // form partial sums. in + // the last run through + // avoid accessing + // non-existent values + // and exit early instead + if (i == step_sizes[0].size()) + break; + x += step_sizes[0][i]; } break; @@ -602,15 +611,22 @@ subdivided_hyper_rectangle(Triangulation &tria, case 2: { double y=0; - for (unsigned int j=0; j<=step_sizes[1].size(); ++j) + for (unsigned int j=0; ; ++j) { double x=0; - for (unsigned int i=0; i<=step_sizes[0].size(); ++i) + for (unsigned int i=0; ; ++i) { points.push_back (Point (p1[0]+x, p1[1]+y)); + if (i == step_sizes[0].size()) + break; + x += step_sizes[0][i]; } + + if (j == step_sizes[1].size()) + break; + y += step_sizes[1][j]; } break; @@ -619,21 +635,32 @@ subdivided_hyper_rectangle(Triangulation &tria, case 3: { double z=0; - for (unsigned int k=0; k<=step_sizes[2].size(); ++k) + for (unsigned int k=0; ; ++k) { double y=0; - for (unsigned int j=0; j<=step_sizes[1].size(); ++j) + for (unsigned int j=0; ; ++j) { double x=0; - for (unsigned int i=0; i<=step_sizes[0].size(); ++i) + for (unsigned int i=0; ; ++i) { points.push_back (Point (p1[0]+x, p1[1]+y, p1[2]+z)); + if (i == step_sizes[0].size()) + break; + x += step_sizes[0][i]; } + + if (j == step_sizes[1].size()) + break; + y += step_sizes[1][j]; } + + if (k == step_sizes[2].size()) + break; + z += step_sizes[2][k]; } break; -- 2.39.5