Bug: list can enter an invalid state, causing a hang due to infinite loop
HSNB opened this issue · 1 comments
HSNB commented
Hi there,
number_of_erased_nodes
can overflow and then cause problems in the next push_back/insert.
Add assert here:
insert(position, *it++);
assert(node_allocator_pair.number_of_erased_nodes != 0); //<-- add this assert to catch the point in time at which it will overflow
--node_allocator_pair.number_of_erased_nodes;
This code will reproduce the hang:
#include "plf_list.h"
int main()
{
plf::list<int> list_one;
list_one.push_back(1);
list_one.push_back(2);
plf::list<int> error_list;
error_list.push_back(1);
error_list.push_back(2);
error_list.push_back(3);
error_list.push_back(4);
error_list.erase(std::remove_if(error_list.begin(), error_list.end(), [](const auto i) { return i == 2 || i == 3; } ), error_list.end()); //<-- in here number_of_erased_nodes becomes 2 which will then cause the invalid state to happen in next call
error_list.insert(error_list.end(), list_one.begin(), list_one.end()); //<-- invalid state caused in here
error_list.push_back(5); //<-- hangs in here (infinite loop somewhere else in the code because number_of_erased_nodes became 18446744073...)
}
Thanks
mattreecebentley commented
Thank you - fixed now - there was a bug in fill/range insert - Cheers!