We need to break out of the loop in factorize_hwtable() as
soon as we have removed a duplicate. Otherwise we might run
onto an deleted element in the outer loop.
Also we should declare factorize_hwtable() as 'void'
as it doesn't return anything.
Signed-off-by: Hannes Reinecke <hare@suse.de>
factorize_hwtable (vector hw, int n)
{
struct hwentry *hwe1, *hwe2;
int i, j;
factorize_hwtable (vector hw, int n)
{
struct hwentry *hwe1, *hwe2;
int i, j;
vector_foreach_slot(hw, hwe1, i) {
if (i == n)
break;
vector_foreach_slot(hw, hwe1, i) {
if (i == n)
break;
merge_hwe(hwe2, hwe1);
if (hwe_strmatch(hwe2, hwe1) == 0) {
vector_del_slot(hw, i);
merge_hwe(hwe2, hwe1);
if (hwe_strmatch(hwe2, hwe1) == 0) {
vector_del_slot(hw, i);
- free_hwe(hwe1);
- n -= 1;
- i -= 1;
- break;
+ /*
+ * Play safe here; we have modified
+ * the original vector so the outer
+ * vector_foreach_slot() might
+ * become confused.
+ */
+ goto restart;