[vlc-devel] [PATCH] demux: es: Replace swab(3) with own implementation

CapacitorSet capacitorset at gmail.com
Sun Feb 18 23:41:32 CET 2018


This is a fix for https://trac.videolan.org/vlc/ticket/19673, where swab(3) was being used incorrectly as an in-place operation. It replaces
the usage of swab(3) with a custom implementation.
---
 modules/demux/mpeg/es.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/modules/demux/mpeg/es.c b/modules/demux/mpeg/es.c
index 5d646ac2c4..4b579a7f28 100644
--- a/modules/demux/mpeg/es.c
+++ b/modules/demux/mpeg/es.c
@@ -498,8 +498,13 @@ static bool Parse( demux_t *p_demux, block_t **pp_output )
     {
         if( p_sys->codec.b_use_word && !p_sys->b_big_endian && p_block_in->i_buffer > 0 )
         {
-            /* Convert to big endian */
-            swab( p_block_in->p_buffer, p_block_in->p_buffer, p_block_in->i_buffer );
+            /* Convert to big endian using a handmade version of swab(3) */
+            for( size_t i = 1; i < p_block_in->i_buffer; i++ )
+            {
+                uint8_t p_tmp = p_block_in->p_buffer[i];
+                p_block_in->p_buffer[i] = p_block_in->p_buffer[i - 1];
+                p_block_in->p_buffer[i - 1] = p_tmp;
+            }
         }
 
         p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start || p_sys->b_initial_sync_failed ? VLC_TS_0 : VLC_TS_INVALID;
-- 
2.16.1



More information about the vlc-devel mailing list