TheochemUI / eOn

eOn v3 and beyond
https://theochemui.github.io/eOn/
BSD 3-Clause "New" or "Revised" License
2 stars 2 forks source link

BUG: INIFile reader has out of access conditionals #110

Closed HaoZeke closed 2 months ago

HaoZeke commented 2 months ago
gcc/x86_64-conda-linux-gnu/12.3.0/include/c++/bits/basic_string.h:1229: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&; size_type = long unsigned int]: Assertion '__pos <= size()' failed.

When compiled with -g -O0 since:

bool CIniFile::ReadFile(FILE *file) {
  string line;
  string keyname, valuename, value;
  string::size_type pLeft, pRight;

  char buff[BUFF_SIZE];
  while (fgets(buff, BUFF_SIZE, file)) {
    // To be compatible with Win32, check for existence of '\r'.
    // Win32 files have the '\r' and Unix files don't at the end of a line.
    // Note that the '\r' will be written to INI files from
    // Unix so that the created INI file can be read under Win32
    // without change.

    string line(buff);

    if (line[line.length() - 1] == '\n')
      line = line.substr(0, line.length() - 1);
    if (line[line.length() - 1] == '\r')
      line = line.substr(0, line.length() - 1);

Can go below the size of the string.

For:

[Main]
job = saddle_search
finite_difference = 0.001

[Potential]
potential = morse_pt

[Optimizer]
opt_method=lbfgs
converged_force = 0.001
max_iterations = 1000

[Saddle Search]
min_mode_method=dimer

[Dimer]
converged_angle=5.0
rotations_max=10

Which is from the optbench Pt Heptamer island..

Should be closed by #86.

HaoZeke commented 2 months ago

Actually seems to be a compiler stack thing. Doesn't happen on older compilers..

gcc version 11.4.0 (conda-forge gcc 11.4.0-0) # Works