]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Check an index in ConstraintMatrix::add_entry. 4168/head
authorDavid Wells <wellsd2@rpi.edu>
Fri, 31 Mar 2017 18:46:45 +0000 (14:46 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Fri, 31 Mar 2017 18:46:45 +0000 (14:46 -0400)
Without this check one can get segmentation faults in debug mode if the
current line is not present.

include/deal.II/lac/constraint_matrix.h

index 328f7a48d898e10e5285a31c36bb753a3bb38ad5..ba56b639732cf840f949358d7dfab303af7336bd 100644 (file)
@@ -1469,16 +1469,23 @@ ConstraintMatrix::add_entry (const size_type line,
   Assert (line != column,
           ExcMessage ("Can't constrain a degree of freedom to itself"));
 
+  // Ensure that the current line is present in the cache:
+  const size_type line_index = calculate_line_index(line);
+  Assert (line_index < lines_cache.size(),
+          ExcMessage("The current ConstraintMatrix does not contain the line "
+                     "for the current entry. Call ConstraintMatrix::add_line "
+                     "before calling this function."));
+
   // if in debug mode, check whether an entry for this column already exists
   // and if it's the same as the one entered at present
   //
   // in any case: exit the function if an entry for this column already
   // exists, since we don't want to enter it twice
-  Assert (lines_cache[calculate_line_index(line)] != numbers::invalid_size_type,
+  Assert (lines_cache[line_index] != numbers::invalid_size_type,
           ExcInternalError());
   Assert (!local_lines.size() || local_lines.is_element(column),
           ExcColumnNotStoredHere(line, column));
-  ConstraintLine *line_ptr = &lines[lines_cache[calculate_line_index(line)]];
+  ConstraintLine *line_ptr = &lines[lines_cache[line_index]];
   Assert (line_ptr->line == line, ExcInternalError());
   for (ConstraintLine::Entries::const_iterator
        p=line_ptr->entries.begin();

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.