michael-hartmann / caps

The Casimir Effect in the plane-sphere geometry.
GNU General Public License v2.0
4 stars 1 forks source link

Avoid crashes when compiling with MSVC #146

Closed michael-hartmann closed 4 years ago

michael-hartmann commented 4 years ago

As far as I understand, remaining_row_ind.end() returns an iterator one past the end of the set. Dereferencing the iterator is thus undefined behaviour.

While the current code (surprisingly) worked on Linux with different versions of gcc, clang, and icc, the code crashes on Windows when I compile it with Visual Studio (MSVC).

Therefore, before dereferencing the iterator, the change decrements the iterator by one to get the last element of the set.

The change seems to fix the problem: The code still works on Linux and no longer crashes on Windows. I have tested the changes on Linux with my test suite computing more than 50 determinants.

See also: https://github.com/sivaramambikasaran/HODLR/pull/39