[libdvbpsi-devel] dvbpsi.c: fix bug in dvbpsi_decoder_psi_section_add()
Jean-Paul Saman
git at videolan.org
Wed Aug 15 16:18:02 CEST 2012
libdvbpsi | branch: master | Jean-Paul Saman <jean-paul.saman at m2x.nl> | Wed Aug 15 16:07:55 2012 +0200| [5c3b697f4fc14b92e34b858abcf69378284bee3f] | committer: 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: 57c6cd6360106fe6ca9738d2fc52a2a87ad276cb)
> http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=5c3b697f4fc14b92e34b858abcf69378284bee3f
---
src/dvbpsi.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/dvbpsi.c b/src/dvbpsi.c
index e07623e..e4aa4ae 100644
--- a/src/dvbpsi.c
+++ b/src/dvbpsi.c
@@ -238,16 +238,19 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect
{
assert(p_decoder);
assert(p_section);
+ assert(p_section->p_next == NULL);
+ /* Empty list */
if (!p_decoder->p_sections)
{
p_decoder->p_sections = p_section;
+ p_section->p_next = NULL;
return false;
}
/* Insert in right place */
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;
while (p)
@@ -260,14 +263,22 @@ bool dvbpsi_decoder_psi_section_add(dvbpsi_decoder_t *p_decoder, dvbpsi_psi_sect
p->p_next = NULL;
dvbpsi_DeletePSISections(p);
b_overwrite = true;
- break;
+ goto out;
}
else if (p->i_number > p_section->i_number)
{
- /* Insert */
- p_prev->p_next = p_section;
- p_section->p_next = p;
- break;
+ /* Insert before p */
+ if (p_prev)
+ {
+ p_prev->p_next = p_section;
+ p_section->p_next = p;
+ }
+ else
+ {
+ p_section->p_next = p;
+ p_decoder->p_sections = p_section;
+ }
+ goto out;
}
p_prev = p;
@@ -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)
{
p_prev->p_next = p_section;
+ p_section->p_next = NULL;
}
+out:
return b_overwrite;
}
More information about the libdvbpsi-devel
mailing list