fix extremely common crash when synonyms file was not set during query

This commit is contained in:
Jean-Francois Dockes 2021-01-16 19:20:30 +01:00
parent baf2ee8d6b
commit 987c9f0950

View File

@ -60,6 +60,18 @@ public:
} }
return st.st_mtime == st1.st_mtime && st.st_size == st1.st_size; return st.st_mtime == st1.st_mtime && st.st_size == st1.st_size;
} }
void clear() {
ok = false;
terms.clear();
groups.clear();
multiwords.clear();
multiwords_maxlen = 0;
path.clear();
st.st_mtime = 0;
st.st_size = 0;
}
bool ok{false}; bool ok{false};
// Term to group num // Term to group num
std::unordered_map<string, unsigned int> terms; std::unordered_map<string, unsigned int> terms;
@ -94,16 +106,11 @@ bool SynGroups::setfile(const string& fn)
{ {
LOGDEB("SynGroups::setfile(" << fn << ")\n"); LOGDEB("SynGroups::setfile(" << fn << ")\n");
if (!m) { if (!m) {
m = new Internal; return false;
if (!m) {
LOGERR("SynGroups:setfile:: new Internal failed: no mem ?\n");
return false;
}
} }
if (fn.empty()) { if (fn.empty()) {
delete m; m->clear();
m = 0;
return true; return true;
} }
@ -125,10 +132,7 @@ bool SynGroups::setfile(const string& fn)
string line; string line;
bool eof = false; bool eof = false;
int lnum = 0; int lnum = 0;
m->groups.clear(); m->clear();
m->terms.clear();
m->multiwords.clear();
m->multiwords_maxlen = 0;
for (;;) { for (;;) {
cline.clear(); cline.clear();
getline(input, cline); getline(input, cline);
@ -256,5 +260,6 @@ size_t SynGroups::getmultiwordsmaxlength() const
const std::string& SynGroups::getpath() const const std::string& SynGroups::getpath() const
{ {
return m->path; static string empty;
return m ? m->path : empty;
} }