[vlc-commits] [Git][videolan/vlc][master] 10 commits: packetizer: avoid pointer casting to copy a value

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jan 27 13:03:51 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
339f1862 by Steve Lhomme at 2025-01-27T12:44:57+00:00
packetizer: avoid pointer casting to copy a value

- - - - -
9a9492d8 by Steve Lhomme at 2025-01-27T12:44:57+00:00
mmal: avoid pointer casting to copy a value

- - - - -
b5459692 by Steve Lhomme at 2025-01-27T12:44:57+00:00
xcb: avoid pointer casting to copy a value

- - - - -
d6225590 by Steve Lhomme at 2025-01-27T12:44:57+00:00
stats: avoid pointer casting to copy a value

- - - - -
a97a5069 by Steve Lhomme at 2025-01-27T12:44:57+00:00
win_msg: avoid pointer casting to copy a value

- - - - -
61a0e03c by Steve Lhomme at 2025-01-27T12:44:57+00:00
win32/specific: avoid pointer casting to copy a value

- - - - -
961562d0 by Steve Lhomme at 2025-01-27T12:44:57+00:00
playlist/request: avoid pointer casting to copy a value

- - - - -
a4563d7d by Steve Lhomme at 2025-01-27T12:44:57+00:00
dmo: avoid copying data in casted structure

We can copy the known size without pointer casting.

- - - - -
620eaa05 by Steve Lhomme at 2025-01-27T12:44:57+00:00
dmo: remove unused variable write

We don't use the content of the VIDEOINFOHEADER in the loop.
There is another loop later doing the same thing.

- - - - -
b606a740 by Steve Lhomme at 2025-01-27T12:44:57+00:00
sapi: remove unneeded forward declaration

Fixes this odd warning:
```
vlc/modules/text_renderer/sapi.cpp:64:12: warning: unused function 'RenderTextMTA' [-Wunused-function]
   64 | static int RenderTextMTA(filter_t *, subpicture_region_t *);
      |            ^~~~~~~~~~~~~
```

- - - - -


12 changed files:

- modules/codec/dmo/dmo.c
- modules/control/win_msg.c
- modules/hw/mmal/codec.c
- modules/hw/mmal/converter.c
- modules/hw/mmal/deinterlace.c
- modules/hw/mmal/vout.c
- modules/misc/stats.c
- modules/packetizer/startcode_helper.h
- modules/text_renderer/sapi.cpp
- modules/video_output/xcb/xkb.c
- src/playlist/request.c
- src/win32/specific.c


Changes:

=====================================
modules/codec/dmo/dmo.c
=====================================
@@ -1078,8 +1078,6 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     i = 0;
     while( !IMediaObject_GetInputType( p_dmo, 0, i++, &dmo_type ) )
     {
-        p_vih = (VIDEOINFOHEADER *)dmo_type.pbFormat;
-
         msg_Dbg( p_enc, "available input chroma: %4.4s",
                  (char *)&dmo_type.subtype.Data1 );
         if( !memcmp( &dmo_type.subtype, &MEDIASUBTYPE_RGB565, 16 ) )
@@ -1157,8 +1155,8 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     }
 
     IMediaObject_GetOutputType( p_dmo, 0, i_selected, &dmo_type );
-    ((VIDEOINFOHEADER *)dmo_type.pbFormat)->dwBitRate =
-        p_enc->fmt_out.i_bitrate;
+    memcpy( dmo_type.pbFormat + offsetof(VIDEOINFOHEADER, dwBitRate),
+            &(DWORD){ p_enc->fmt_out.i_bitrate }, sizeof(DWORD) );
 
     /* Get the private data for the codec */
     while( 1 )


=====================================
modules/control/win_msg.c
=====================================
@@ -91,13 +91,15 @@ static LRESULT CALLBACK WMCOPYWNDPROC(HWND hwnd, UINT uMsg,
             char **ppsz_argv;
             vlc_ipc_data_t *p_data = (vlc_ipc_data_t *)pwm_data->lpData;
             size_t i_data = 0;
+            size_t i_len;
             int i_argc = p_data->argc, i_opt, i_options;
 
             ppsz_argv = vlc_alloc( i_argc, sizeof(char *) );
             for( i_opt = 0; i_opt < i_argc; i_opt++ )
             {
-                ppsz_argv[i_opt] = p_data->data + i_data + sizeof(size_t);
-                i_data += sizeof(size_t) + *((size_t *)(p_data->data + i_data));
+                memcpy( &i_len, &p_data->data[i_data], sizeof(size_t) );
+                ppsz_argv[i_opt] = &p_data->data[i_data] + sizeof(size_t);
+                i_data += sizeof(size_t) + i_len;
             }
 
             for( i_opt = 0; i_opt < i_argc; i_opt++ )


=====================================
modules/hw/mmal/codec.c
=====================================
@@ -208,7 +208,7 @@ static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     MMAL_STATUS_T status;
 
     if (buffer->cmd == MMAL_EVENT_ERROR) {
-        status = *(uint32_t *)buffer->data;
+        memcpy(&status, buffer->data, sizeof(status));
         decoder_sys_t * const sys = dec->p_sys;
         sys->err_stream = status;
         msg_Err(dec, "MMAL error %"PRIx32" \"%s\"", status,


=====================================
modules/hw/mmal/converter.c
=====================================
@@ -250,7 +250,8 @@ static void conv_control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer
     filter_t * const p_filter = (filter_t *)port->userdata;
 
     if (buffer->cmd == MMAL_EVENT_ERROR) {
-        MMAL_STATUS_T status = *(uint32_t *)buffer->data;
+        MMAL_STATUS_T status;
+        memcpy(&status, buffer->data, sizeof(status));
 
         converter_sys_t * sys = p_filter->p_sys;
         sys->err_stream = status;
@@ -985,4 +986,3 @@ fail:
 
     return ret;
 }
-


=====================================
modules/hw/mmal/deinterlace.c
=====================================
@@ -358,7 +358,7 @@ static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     MMAL_STATUS_T status;
 
     if (buffer->cmd == MMAL_EVENT_ERROR) {
-        status = *(uint32_t *)buffer->data;
+        memcpy(&status, buffer->data, sizeof(status));
         msg_Err(filter, "MMAL error %"PRIx32" \"%s\"", status,
                 mmal_status_to_string(status));
     }


=====================================
modules/hw/mmal/vout.c
=====================================
@@ -225,7 +225,7 @@ static void isp_control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     MMAL_STATUS_T status;
 
     if (buffer->cmd == MMAL_EVENT_ERROR) {
-        status = *(uint32_t *)buffer->data;
+        memcpy(&status, buffer->data, sizeof(status));
         msg_Err(vd, "MMAL error %"PRIx32" \"%s\"", status, mmal_status_to_string(status));
     }
 
@@ -755,7 +755,7 @@ static void vd_control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     MMAL_STATUS_T status;
 
     if (buffer->cmd == MMAL_EVENT_ERROR) {
-        status = *(uint32_t *)buffer->data;
+        memcpy(&status, buffer->data, sizeof(status));
         msg_Err(vd, "MMAL error %"PRIx32" \"%s\"", status, mmal_status_to_string(status));
     }
 


=====================================
modules/misc/stats.c
=====================================
@@ -52,19 +52,21 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
     if( !p_pic )
         goto error;
 
+    vlc_tick_t tick;
     if( p_block->i_buffer == kBufferSize )
     {
+        memcpy(&tick, p_block->p_buffer, sizeof(vlc_tick_t));
         msg_Dbg( p_dec, "got %"PRIu64" ms",
-                 MS_FROM_VLC_TICK(*(vlc_tick_t *)p_block->p_buffer) );
+                 MS_FROM_VLC_TICK(tick) );
         msg_Dbg( p_dec, "got %"PRIu64" ms offset",
-                 MS_FROM_VLC_TICK(vlc_tick_now() - *(vlc_tick_t *)p_block->p_buffer) );
-        *(vlc_tick_t *)(p_pic->p->p_pixels) = *(vlc_tick_t *)p_block->p_buffer;
+                 MS_FROM_VLC_TICK(vlc_tick_now() - tick) );
     }
     else
     {
         msg_Dbg( p_dec, "got a packet not from stats demuxer" );
-        *(vlc_tick_t *)(p_pic->p->p_pixels) = vlc_tick_now();
+        tick = vlc_tick_now();
     }
+    memcpy(p_pic->p->p_pixels, &tick, sizeof(vlc_tick_t));
 
     p_pic->date = p_block->i_pts != VLC_TICK_INVALID ?
             p_block->i_pts : p_block->i_dts;
@@ -101,13 +103,14 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
     (void)p_pict;
     block_t * p_block = block_Alloc( kBufferSize );
 
-    *(vlc_tick_t*)p_block->p_buffer = vlc_tick_now();
+    vlc_tick_t now = vlc_tick_now();
+    memcpy(p_block->p_buffer, &now, sizeof(vlc_tick_t));
     p_block->i_buffer = kBufferSize;
     p_block->i_length = kBufferSize;
     p_block->i_dts = p_pict->date;
 
     msg_Dbg( p_enc, "putting %"PRIu64"ms",
-             MS_FROM_VLC_TICK(*(vlc_tick_t*)p_block->p_buffer) );
+             MS_FROM_VLC_TICK(now) );
     return p_block;
 }
 
@@ -164,8 +167,10 @@ static int Demux( demux_t *p_demux )
 
     p_block->i_dts = p_block->i_pts = date_Increment( &p_sys->pts, kBufferSize );
 
+    vlc_tick_t tick;
+    memcpy(&tick, p_block->p_buffer, sizeof(vlc_tick_t));
     msg_Dbg( p_demux, "demux got %"PRId64" ms offset",
-             MS_FROM_VLC_TICK(vlc_tick_now() - *(vlc_tick_t *)p_block->p_buffer) );
+             MS_FROM_VLC_TICK(vlc_tick_now() - tick) );
 
     //es_out_SetPCR( p_demux->out, p_block->i_pts );
 


=====================================
modules/packetizer/startcode_helper.h
=====================================
@@ -133,7 +133,8 @@ static inline const uint8_t * startcode_FindAnnexB_Bits( const uint8_t *p, const
     }
 
     for (end -= 3; p < end; p += 4) {
-        uint32_t x = *(const uint32_t*)p;
+        uint32_t x;
+        memcpy(&x, p, sizeof(x));
         if ((x - 0x01010101) & (~x) & 0x80808080)
         {
             /* matching DW isn't faster */


=====================================
modules/text_renderer/sapi.cpp
=====================================
@@ -61,8 +61,6 @@ static subpicture_region_t *RenderText(filter_t *,
                       const vlc_fourcc_t *);
 }
 
-static int RenderTextMTA(filter_t *, subpicture_region_t *);
-
 vlc_module_begin ()
  set_description(N_("Speech synthesis for Windows"))
 


=====================================
modules/video_output/xcb/xkb.c
=====================================
@@ -35,10 +35,14 @@
 
 static int keysymcmp (const void *pa, const void *pb)
 {
-    int a = *(const uint32_t *)pa;
-    int b = *(const uint32_t *)pb;
-
-    return a - b;
+    const uint32_t *a = pa;
+    const uint32_t *b = pb;
+
+    if (*a == *b)
+        return 0;
+    if (*a > *b)
+        return 1;
+    return -1;
 }
 
 static uint_fast32_t vlc_xkb_convert_keysym(uint_fast32_t sym)


=====================================
src/playlist/request.c
=====================================
@@ -192,11 +192,11 @@ vlc_playlist_MoveBySlices(vlc_playlist_t *playlist, size_t indices[],
 static int
 cmp_size(const void *lhs, const void *rhs)
 {
-    size_t a = *(size_t *) lhs;
-    size_t b = *(size_t *) rhs;
-    if (a < b)
+    const size_t *a = lhs;
+    const size_t *b = rhs;
+    if (*a < *b)
         return -1;
-    if (a == b)
+    if (*a == *b)
         return 0;
     return 1;
 }


=====================================
src/win32/specific.c
=====================================
@@ -138,9 +138,7 @@ void system_Configure( libvlc_int_t *p_this, int i_argc, const char *const ppsz_
                 for( i_opt = 0; i_opt < i_argc; i_opt++ )
                 {
                     size_t i_len = strlen( ppsz_argv[ i_opt ] ) + 1;
-                    /* Windows will never switch to an architecture
-                     * with stronger alignment requirements, right. */
-                    *((size_t *)(p_data->data + i_data)) = i_len;
+                    memcpy( &p_data->data[i_data], &i_len, sizeof (size_t) );
                     i_data += sizeof (size_t);
                     memcpy( &p_data->data[i_data], ppsz_argv[ i_opt ], i_len );
                     i_data += i_len;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/76dee6106e1c9fb5eb1ac584f99a0e1389c8e13c...b606a740e85520f3f1e6f49811ef71da14ea13e1

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/76dee6106e1c9fb5eb1ac584f99a0e1389c8e13c...b606a740e85520f3f1e6f49811ef71da14ea13e1
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list