filter: Check for empty results when filtering
The user could search for a term that isn't stored in the filter index. This is represented through a NULL pointer returned from the Index.find() function. Let's check this pointer before attempting to dereference it ... Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
b9c3d9684c
commit
be72339b2d
|
@ -90,14 +90,21 @@ std::string filter :: add(const std::string &text, unsigned int track_id)
|
|||
return reassemble_text(parsed);
|
||||
}
|
||||
|
||||
static void do_set_intersection(std::set<unsigned int> &a,
|
||||
std::set<unsigned int> &b,
|
||||
std::set<unsigned int> &res)
|
||||
{
|
||||
set_intersection(a.begin(), a.end(), b.begin(), b.end(),
|
||||
std::inserter<std::set<unsigned int> >(res, res.begin()));
|
||||
}
|
||||
|
||||
static void find_intersection(std::string &text, std::set<unsigned int> &res)
|
||||
{
|
||||
IndexEntry *it = filter_index.find(text);
|
||||
std::set<unsigned int> tmp;
|
||||
IndexEntry *it = filter_index.find(text);
|
||||
|
||||
set_intersection(it->values.begin(), it->values.end(),
|
||||
res.begin(), res.end(),
|
||||
std::inserter<std::set<unsigned int> >(tmp, tmp.begin()));
|
||||
if (it)
|
||||
do_set_intersection(res, it->values, tmp);
|
||||
res.swap(tmp);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,9 @@ static void test_search()
|
|||
|
||||
unsigned int res5[] = {};
|
||||
do_test_search("unknown terms", 0, res5);
|
||||
|
||||
unsigned int res6[] = {};
|
||||
do_test_search("the chestZ", 0, res6);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Reference in New Issue