I met a crash when I try to read content from a plain file.
#5 0x0d0bef60 in std::__throw_ios_failure(char const*) () from /usr/lib/libstdc++.so.6
#6 0x0d0c2d38 in std::basic_filebuf<char, std::char_traits<char> >::underflow() () from /usr/lib/libstdc++.so.6
#7 0x0d075454 in std::istream::sentry::sentry(std::istream&, bool) () from /usr/lib/libstdc++.so.6
#8 0x0d077510 in std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, char&) () from /usr/lib/libstdc++.so.6
#9 0x0fc638dc in GetOpenMode () at /home/nvbldr/workspace/working_dir/BaseServices/Utils/src/Misc_func.cpp:38
The code is below:
#define OPEN_ENABLED_FILE"/var/open_mode"
char isOpenMode = default_mode;
fstream openModeFile;
char buff[2];
memset(buff, 0, 2);
openModeFile.open(OPEN_ENABLED_FILE, ios::in);
if (!openModeFile)
{
isOpenMode = non_open_mode;
}
else
{
openModeFile>> buff[0]; // Seems this line crashed.
isOpenMode = buff[0] == '1' ? open_mode : non_open_mode;
openModeFile.close();
}
I cannot see why, this not always happen. We are doing some stress test for 20 hours, only happned in one stress test. Can anyone help give some advice, thanks.
question from:
https://stackoverflow.com/questions/65912205/fstream-operator-sometime-crash 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…