From: bangerth Date: Mon, 17 Mar 2008 05:39:51 +0000 (+0000) Subject: Avoid accessing elements of vectors beyond the end even if the result is not used... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c91e960bdab3bfbf720f465129710ebfa8456965;p=dealii-svn.git 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 --- 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;