Commit 5c3b697f authored by Jean-Paul Saman's avatar Jean-Paul Saman

dvbpsi.c: fix bug in dvbpsi_decoder_psi_section_add()

Inserting a new PSI section did not take into account that the previous
pointer could be none existing. It was equal to the start of the list,
which resulted in a loop.

(Fixes commit: 57c6cd63)
parent 8b0c6414
...@@ -238,16 +238,19 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect ...@@ -238,16 +238,19 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect
{ {
assert(p_decoder); assert(p_decoder);
assert(p_section); assert(p_section);
assert(p_section->p_next == NULL);
/* Empty list */
if (!p_decoder->p_sections) if (!p_decoder->p_sections)
{ {
p_decoder->p_sections = p_section; p_decoder->p_sections = p_section;
p_section->p_next = NULL;
return false; return false;
} }
/* Insert in right place */ /* Insert in right place */
dvbpsi_psi_section_t *p = p_decoder->p_sections; dvbpsi_psi_section_t *p = p_decoder->p_sections;
dvbpsi_psi_section_t *p_prev = p; dvbpsi_psi_section_t *p_prev = NULL;
bool b_overwrite = false; bool b_overwrite = false;
while (p) while (p)
...@@ -260,14 +263,22 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect ...@@ -260,14 +263,22 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect
p->p_next = NULL; p->p_next = NULL;
dvbpsi_DeletePSISections(p); dvbpsi_DeletePSISections(p);
b_overwrite = true; b_overwrite = true;
break; goto out;
} }
else if (p->i_number > p_section->i_number) else if (p->i_number > p_section->i_number)
{ {
/* Insert */ /* Insert before p */
if (p_prev)
{
p_prev->p_next = p_section; p_prev->p_next = p_section;
p_section->p_next = p; p_section->p_next = p;
break; }
else
{
p_section->p_next = p;
p_decoder->p_sections = p_section;
}
goto out;
} }
p_prev = p; p_prev = p;
...@@ -278,8 +289,10 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect ...@@ -278,8 +289,10 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect
if (p_prev->i_number < p_section->i_number) if (p_prev->i_number < p_section->i_number)
{ {
p_prev->p_next = p_section; p_prev->p_next = p_section;
p_section->p_next = NULL;
} }
out:
return b_overwrite; return b_overwrite;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment