[vlc-commits] ogg: avoid bad casts in DEMUX_GET_POSITION

Rémi Denis-Courmont git at videolan.org
Sun Mar 3 10:25:04 CET 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar  3 09:52:36 2019 +0200| [41b9d3e65a281ee38b38d8f2141d236522a06f46] | committer: Rémi Denis-Courmont

ogg: avoid bad casts in DEMUX_GET_POSITION

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

 modules/demux/ogg.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/modules/demux/ogg.c b/modules/demux/ogg.c
index 67be875701..b57bf968ca 100644
--- a/modules/demux/ogg.c
+++ b/modules/demux/ogg.c
@@ -672,7 +672,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     demux_sys_t *p_sys  = p_demux->p_sys;
     vlc_meta_t *p_meta;
     vlc_tick_t i64;
-    double *pf, f;
+    double f;
     bool *pb_bool, b, acc;
     logical_stream_t *p_stream;
 
@@ -745,19 +745,24 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             return VLC_SUCCESS;
         }
 
-        case DEMUX_GET_POSITION:
-            pf = va_arg( args, double * );
+        case DEMUX_GET_POSITION: {
+            double pos = 0.;
+            uint64_t size;
+
             if( p_sys->i_length > 0 && p_sys->i_pcr != VLC_TICK_INVALID )
             {
-                *pf =  (double) p_sys->i_pcr /
-                       (double) vlc_tick_from_sec( p_sys->i_length );
+                vlc_tick_t duration = vlc_tick_from_sec( p_sys->i_length );
+                pos = (double) p_sys->i_pcr / (double) duration;
             }
-            else if( stream_Size( p_demux->s ) > 0 )
+            else if( vlc_stream_GetSize( p_demux->s, &size ) == 0 && size > 0 )
             {
-                *pf = (double) vlc_stream_Tell( p_demux->s ) / stream_Size( p_demux->s );
+                uint64_t offset = vlc_stream_Tell( p_demux->s );
+                pos = (double) offset / (double) size;
             }
-            else *pf = 0.0;
+
+            *va_arg( args, double * ) = pos;
             return VLC_SUCCESS;
+        }
 
         case DEMUX_SET_POSITION:
             /* forbid seeking if we haven't initialized all logical bitstreams yet;



More information about the vlc-commits mailing list