[vlc-commits] chromecast: Fix undefined behavior in case of error

Hugo Beauzée-Luyssen git at videolan.org
Thu Feb 16 09:54:11 CET 2017


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Feb 15 15:03:20 2017 +0100| [e9ccb209631f1382867bc3e31f08e5a664519c80] | committer: Hugo Beauzée-Luyssen

chromecast: Fix undefined behavior in case of error

Removing an element from a container and using the iterator pointing to
the removed element afterward is UB

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9ccb209631f1382867bc3e31f08e5a664519c80
---

 modules/stream_out/chromecast/cast.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 2b9ccf1..89fe911 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -317,15 +317,17 @@ int sout_stream_sys_t::UpdateOutput( sout_stream_t *p_stream )
         }
 
         /* check the streams we can actually add */
-        for (std::vector<sout_stream_id_sys_t*>::iterator it = streams.begin(); it != streams.end(); ++it)
+        for (std::vector<sout_stream_id_sys_t*>::iterator it = streams.begin(); it != streams.end(); )
         {
             sout_stream_id_sys_t *p_sys_id = *it;
             p_sys_id->p_sub_id = sout_StreamIdAdd( p_out, &p_sys_id->fmt );
             if ( p_sys_id->p_sub_id == NULL )
             {
                 msg_Err( p_stream, "can't handle %4.4s stream", (char *)&p_sys_id->fmt.i_codec );
-                streams.erase( it, it );
+                it = streams.erase( it );
             }
+            else
+                ++it;
         }
 
         if ( !streams.empty() )



More information about the vlc-commits mailing list