[vlc-commits] [Git][videolan/vlc][master] 2 commits: win32: don't get the COM interface pointers directly

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Wed Nov 17 19:44:43 UTC 2021



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
e99f23d5 by Steve Lhomme at 2021-11-17T17:31:34+00:00
win32: don't get the COM interface pointers directly

We can't really use an interface** where a void** is expected, that's a
cast/aliasing violation, even though that's what Windows and mingw64 API's do
as well.

We use an interim void* variable that receives the pointer and then set it on
the proper variable with the given type.

Fixes #26083

- - - - -
33015966 by Rémi Denis-Courmont at 2021-11-17T17:31:34+00:00
winstore: fix invalid pointer aliasing

- - - - -


10 changed files:

- modules/audio_output/directsound.c
- modules/audio_output/winstore.c
- modules/codec/avcodec/d3d11va.c
- modules/codec/dmo/dmo.c
- modules/codec/mft.c
- modules/hw/d3d11/d3d11_processor.c
- modules/hw/d3d9/d3d9_filters.c
- modules/hw/d3d9/dxva2_deinterlace.c
- modules/video_chroma/d3d11_fmt.c
- src/win32/dirs-uap.c


Changes:

=====================================
modules/audio_output/directsound.c
=====================================
@@ -382,6 +382,7 @@ static HRESULT CreateDSBuffer( vlc_object_t *obj, aout_stream_sys_t *sys,
     WAVEFORMATEXTENSIBLE waveformat;
     DSBUFFERDESC         dsbdesc;
     HRESULT              hr;
+    void                 *pv = NULL;
 
     /* First set the sound buffer format */
     waveformat.dwChannelMask = 0;
@@ -493,8 +494,8 @@ static HRESULT CreateDSBuffer( vlc_object_t *obj, aout_stream_sys_t *sys,
         msg_Dbg( obj, "channel reordering needed" );
 
     hr = IDirectSoundBuffer_QueryInterface( sys->p_dsbuffer,
-                                            &IID_IDirectSoundNotify,
-                                            (void **) &sys->p_notify );
+                                            &IID_IDirectSoundNotify, &pv );
+    sys->p_notify = pv;
     if( hr != DS_OK )
     {
         msg_Err( obj, "Couldn't query IDirectSoundNotify" );


=====================================
modules/audio_output/winstore.c
=====================================
@@ -156,12 +156,14 @@ static void WaitForAudioClient(audio_output_t *aout)
             msg_Dbg(aout, "Failed to get the device instance.");
         else
         {
-            hr = IUnknown_QueryInterface(audioInterface, &IID_IAudioClient, (void**)&sys->client);
+            void *pv;
+            hr = IUnknown_QueryInterface(audioInterface, &IID_IAudioClient, &pv);
             IUnknown_Release(audioInterface);
             if (unlikely(FAILED(hr)))
                 msg_Warn(aout, "The received interface is not a IAudioClient. (hr=0x%lX)", hr);
             else
             {
+                sys->client = pv;
                 sys->acquired_device = wcsdup(devId);
 
                 char *report = FromWide(devId);
@@ -171,9 +173,9 @@ static void WaitForAudioClient(audio_output_t *aout)
                     free(report);
                 }
 
-                IAudioClient2 *audioClient2;
-                if (SUCCEEDED(IAudioClient_QueryInterface(sys->client, &IID_IAudioClient2, (void**)&audioClient2)))
+                if (SUCCEEDED(IAudioClient_QueryInterface(sys->client, &IID_IAudioClient2, &pv)))
                 {
+                    IAudioClient2 *audioClient2 = pv;
                     // "BackgroundCapableMedia" does not work in UWP
                     AudioClientProperties props = (AudioClientProperties) {
                         .cbSize = sizeof(props),
@@ -279,6 +281,7 @@ static int VolumeSet(audio_output_t *aout, float vol)
     if( unlikely( sys->client == NULL ) )
         return VLC_EGENERIC;
     HRESULT hr;
+    void *pv = NULL;
     ISimpleAudioVolume *pc_AudioVolume = NULL;
 
     float linear_vol = vol * vol * vol; /* ISimpleAudioVolume is tapered linearly. */
@@ -293,12 +296,13 @@ static int VolumeSet(audio_output_t *aout, float vol)
 
     aout_GainRequest(aout, sys->gain);
 
-    hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, (void**)&pc_AudioVolume);
+    hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, &pv);
     if (FAILED(hr))
     {
         msg_Err(aout, "cannot get volume service (error 0x%lX)", hr);
         goto done;
     }
+    pc_AudioVolume = pv;
 
     hr = ISimpleAudioVolume_SetMasterVolume(pc_AudioVolume, linear_vol, NULL);
     if (FAILED(hr))
@@ -322,14 +326,16 @@ static int MuteSet(audio_output_t *aout, bool mute)
     if( unlikely( sys->client == NULL ) )
         return VLC_EGENERIC;
     HRESULT hr;
+    void *pv = NULL;
     ISimpleAudioVolume *pc_AudioVolume = NULL;
 
-    hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, (void**)&pc_AudioVolume);
+    hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, &pv);
     if (FAILED(hr))
     {
         msg_Err(aout, "cannot get volume service (error 0x%lX)", hr);
         goto done;
     }
+    pc_AudioVolume = pv;
 
     hr = ISimpleAudioVolume_SetMute(pc_AudioVolume, mute, NULL);
     if (FAILED(hr))
@@ -495,14 +501,16 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     // Report the initial volume and mute status to the core
     if (sys->client != NULL)
     {
-        ISimpleAudioVolume* pc_AudioVolume = NULL;
+        ISimpleAudioVolume *pc_AudioVolume = NULL;
+        void *pv;
 
-        hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, (void**)&pc_AudioVolume);
+        hr = IAudioClient_GetService(sys->client, &IID_ISimpleAudioVolume, &pv);
         if (FAILED(hr))
         {
             msg_Err(aout, "cannot get volume service (error 0x%lx)", hr);
             goto done;
         }
+        pc_AudioVolume = pv;
 
         float vol;
         hr = ISimpleAudioVolume_GetMasterVolume(pc_AudioVolume, &vol);


=====================================
modules/codec/avcodec/d3d11va.c
=====================================
@@ -503,9 +503,10 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
     vlc_va_sys_t *sys = va->sys;
     HRESULT hr;
 
-    ID3D10Multithread *pMultithread;
-    hr = ID3D11Device_QueryInterface( sys->d3d_dev->d3ddevice, &IID_ID3D10Multithread, (void **)&pMultithread);
+    void *pv;
+    hr = ID3D11Device_QueryInterface( sys->d3d_dev->d3ddevice, &IID_ID3D10Multithread, &pv);
     if (SUCCEEDED(hr)) {
+        ID3D10Multithread *pMultithread = pv;
         ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
         ID3D10Multithread_Release(pMultithread);
     }


=====================================
modules/codec/dmo/dmo.c
=====================================
@@ -633,6 +633,7 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     DWORD i_dummy;
 
     GETCLASS GetClass;
+    void *pv;
     IClassFactory *cFactory = NULL;
     IUnknown *cObject = NULL;
     const codec_dll *codecs_table = b_out ? encoders_table : decoders_table;
@@ -691,7 +692,7 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
     }
 
     /* Pickup the first available codec */
-    *pp_dmo = 0;
+    *pp_dmo = NULL;
     while( ( S_OK == IEnumDMO_Next( p_enum_dmo, 1, &clsid_dmo,
                      &psz_dmo_name, &i_dummy /* NULL doesn't work */ ) ) )
     {
@@ -700,13 +701,15 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE *p_hmsdmo_dll,
 
         /* Create DMO */
         if( CoCreateInstance( &clsid_dmo, NULL, CLSCTX_INPROC,
-                              &IID_IMediaObject, (void **)pp_dmo ) )
+                              &IID_IMediaObject, &pv ) )
         {
             msg_Warn( p_this, "can't create DMO" );
-            *pp_dmo = 0;
         }
         else
+        {
+            *pp_dmo = pv;
             break;
+        }
     }
 
     IEnumDMO_Release( p_enum_dmo );
@@ -746,27 +749,25 @@ loader:
         return VLC_EGENERIC;
     }
 
-    i_err = GetClass( codecs_table[i_codec].p_guid, &IID_IClassFactory,
-                      (void**)&cFactory );
+    i_err = GetClass( codecs_table[i_codec].p_guid, &IID_IClassFactory, &pv );
 
-    if( i_err || cFactory == NULL )
+    if( i_err || pv == NULL )
     {
         msg_Dbg( p_this, "no such class object" );
         FreeLibrary( *p_hmsdmo_dll );
         return VLC_EGENERIC;
     }
+    cFactory = pv;
 
-    i_err = IClassFactory_CreateInstance( cFactory, 0, &IID_IUnknown,
-                                          (void**)&cObject );
+    i_err = IClassFactory_CreateInstance( cFactory, 0, &IID_IUnknown, &pv );
     IClassFactory_Release( cFactory );
-    if( i_err || !cObject )
+    if( i_err || !pv )
     {
         msg_Dbg( p_this, "class factory failure" );
         FreeLibrary( *p_hmsdmo_dll );
         return VLC_EGENERIC;
     }
-    i_err = IUnknown_QueryInterface( cObject, &IID_IMediaObject,
-                                        (void**)pp_dmo );
+    i_err = IUnknown_QueryInterface( cObject, &IID_IMediaObject, &pv );
     IUnknown_Release( cObject );
     if( i_err || !*pp_dmo )
     {
@@ -774,6 +775,7 @@ loader:
         FreeLibrary( *p_hmsdmo_dll );
         return VLC_EGENERIC;
     }
+    *pp_dmo = pv;
 
     return VLC_SUCCESS;
 }
@@ -1147,14 +1149,15 @@ static int EncoderSetVideoType( encoder_t *p_enc, IMediaObject *p_dmo )
     /* Get the private data for the codec */
     while( 1 )
     {
+        void *pv;
         IWMCodecPrivateData *p_privdata;
         uint8_t *p_data = 0;
         uint32_t i_data = 0, i_vih;
 
         i_err = IMediaObject_QueryInterface( p_dmo,
-                                           &IID_IWMCodecPrivateData,
-                                           (void**)&p_privdata );
+                                           &IID_IWMCodecPrivateData, &pv );
         if( i_err ) break;
+        p_privdata = pv;
 
         i_err = p_privdata->vt->SetPartialOutputType( p_privdata, &dmo_type );
         if( i_err )


=====================================
modules/codec/mft.c
=====================================
@@ -972,9 +972,11 @@ static int InitializeMFT(decoder_t *p_dec)
             hr = IMFAttributes_SetUINT32(attributes, &MF_TRANSFORM_ASYNC_UNLOCK, true);
             if (FAILED(hr))
                 goto error;
-            hr = IMFTransform_QueryInterface(p_sys->mft, &IID_IMFMediaEventGenerator, (void**)&p_sys->event_generator);
+            void *pv;
+            hr = IMFTransform_QueryInterface(p_sys->mft, &IID_IMFMediaEventGenerator, &pv);
             if (FAILED(hr))
                 goto error;
+            p_sys->event_generator = pv;
         }
     }
 
@@ -1129,12 +1131,14 @@ static int FindMFT(decoder_t *p_dec)
     if (activate_objects_count == 0)
         return VLC_EGENERIC;
 
+    void *pv;
     for (UINT32 i = 0; i < activate_objects_count; ++i)
     {
-        hr = IMFActivate_ActivateObject(activate_objects[i], &IID_IMFTransform, (void**)&p_sys->mft);
+        hr = IMFActivate_ActivateObject(activate_objects[i], &IID_IMFTransform, &pv);
         IMFActivate_Release(activate_objects[i]);
         if (FAILED(hr))
             continue;
+        p_sys->mft = pv;
 
         if (InitializeMFT(p_dec) == VLC_SUCCESS)
         {


=====================================
modules/hw/d3d11/d3d11_processor.c
=====================================
@@ -73,19 +73,22 @@ int D3D11_CreateProcessor(vlc_object_t *o, d3d11_device_t *d3d_dev,
                           d3d11_processor_t *out)
 {
     HRESULT hr;
+    void *pv;
     *out = (d3d11_processor_t) { 0 };
 
-    hr = ID3D11Device_QueryInterface(d3d_dev->d3ddevice, &IID_ID3D11VideoDevice, (void **)&out->d3dviddev);
+    hr = ID3D11Device_QueryInterface(d3d_dev->d3ddevice, &IID_ID3D11VideoDevice, &pv);
     if (FAILED(hr)) {
        msg_Err(o, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
        goto error;
     }
+    out->d3dviddev = pv;
 
-    hr = ID3D11DeviceContext_QueryInterface(d3d_dev->d3dcontext, &IID_ID3D11VideoContext, (void **)&out->d3dvidctx);
+    hr = ID3D11DeviceContext_QueryInterface(d3d_dev->d3dcontext, &IID_ID3D11VideoContext, &pv);
     if (FAILED(hr)) {
        msg_Err(o, "Could not Query ID3D11VideoContext Interface. (hr=0x%lX)", hr);
        goto error;
     }
+    out->d3dvidctx = pv;
 
     D3D11_VIDEO_PROCESSOR_CONTENT_DESC processorDesc = {
         .InputFrameFormat = srcFields,


=====================================
modules/hw/d3d9/d3d9_filters.c
=====================================
@@ -282,6 +282,7 @@ static int D3D9OpenAdjust(filter_t *filter)
     HRESULT hr;
     GUID *processorGUIDs = NULL;
     GUID *processorGUID = NULL;
+    void *pv;
     IDirectXVideoProcessorService *processor = NULL;
 
     if (filter->fmt_in.video.i_chroma != VLC_CODEC_D3D9_OPAQUE
@@ -315,13 +316,14 @@ static int D3D9OpenAdjust(filter_t *filter)
     }
 
     d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueContext(filter->vctx_in);
-    hr = CreateVideoService( d3d9_decoder->d3ddev.dev, &IID_IDirectXVideoProcessorService,
-                            (void**)&processor);
+    hr = CreateVideoService( d3d9_decoder->d3ddev.dev,
+                             &IID_IDirectXVideoProcessorService, &pv);
     if (FAILED(hr))
     {
         msg_Err(filter, "Failed to create the video processor. (hr=0x%lX)", hr);
         goto error;
     }
+    processor = pv;
 
     DXVA2_VideoDesc dsc;
     ZeroMemory(&dsc, sizeof(dsc));


=====================================
modules/hw/d3d9/dxva2_deinterlace.c
=====================================
@@ -346,6 +346,7 @@ int D3D9OpenDeinterlace(filter_t *filter)
     HRESULT hr;
     GUID *processorGUIDs = NULL;
     GUID *processorGUID = NULL;
+    void *pv;
     IDirectXVideoProcessorService *processor = NULL;
 
     if (filter->fmt_in.video.i_chroma != VLC_CODEC_D3D9_OPAQUE
@@ -375,10 +376,11 @@ int D3D9OpenDeinterlace(filter_t *filter)
       (void *)GetProcAddress(hdecoder_dll, "DXVA2CreateVideoService");
     if (CreateVideoService == NULL)
         goto error;
-    hr = CreateVideoService( d3d9_decoder->d3ddev.dev, &IID_IDirectXVideoProcessorService,
-                            (void**)&processor);
+    hr = CreateVideoService( d3d9_decoder->d3ddev.dev,
+                             &IID_IDirectXVideoProcessorService, &pv );
     if (FAILED(hr))
         goto error;
+    processor = pv;
 
     DXVA2_VideoDesc dsc;
     ZeroMemory(&dsc, sizeof(dsc));


=====================================
modules/video_chroma/d3d11_fmt.c
=====================================
@@ -613,11 +613,13 @@ error:
 
 IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev)
 {
-    IDXGIDevice *pDXGIDevice = NULL;
-    HRESULT hr = ID3D11Device_QueryInterface(d3ddev, &IID_IDXGIDevice, (void **)&pDXGIDevice);
+    IDXGIDevice *pDXGIDevice;
+    void *pv;
+    HRESULT hr = ID3D11Device_QueryInterface(d3ddev, &IID_IDXGIDevice, &pv);
     if (FAILED(hr)) {
         return NULL;
     }
+    pDXGIDevice = pv;
 
     IDXGIAdapter *p_adapter;
     hr = IDXGIDevice_GetAdapter(pDXGIDevice, &p_adapter);
@@ -911,9 +913,12 @@ void D3D11_LogResources(d3d11_decoder_device_t *dev_sys)
     d3d11_handle_t *hd3d = &sys->hd3d;
     if (hd3d->pf_DXGIGetDebugInterface)
     {
-        IDXGIDebug *pDXGIDebug;
-        if (SUCCEEDED(hd3d->pf_DXGIGetDebugInterface(&IID_IDXGIDebug, (void**)&pDXGIDebug)))
+        void *pv;
+        if (SUCCEEDED(hd3d->pf_DXGIGetDebugInterface(&IID_IDXGIDebug, &pv)))
+        {
+            IDXGIDebug *pDXGIDebug = pv;
             IDXGIDebug_ReportLiveObjects(pDXGIDebug, DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);
+        }
     }
 # endif
 #endif


=====================================
src/win32/dirs-uap.c
=====================================
@@ -44,10 +44,12 @@
 static char * GetFolderName(IStorageFolder *folder)
 {
     HRESULT hr;
+    void *pv;
     IStorageItem *item;
-    hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, (void**)&item);
+    hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, &pv);
     if (FAILED(hr))
         return NULL;
+    item = pv;
 
     char *result = NULL;
     HSTRING path;
@@ -68,6 +70,7 @@ static char *config_GetShellDir(vlc_userdir_t csidl)
     HRESULT hr;
     IStorageFolder *folder = NULL;
 
+    void *pv;
     IKnownFoldersStatics *knownFoldersStatics = NULL;
     static const WCHAR *className = L"Windows.Storage.KnownFolders";
     const UINT32 clen = wcslen(className);
@@ -78,15 +81,16 @@ static char *config_GetShellDir(vlc_userdir_t csidl)
     if (FAILED(hr))
         goto end_other;
 
-    hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, (void**)&knownFoldersStatics);
+    hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, &pv);
 
     if (FAILED(hr))
         goto end_other;
 
-    if (!knownFoldersStatics) {
+    if (!pv) {
         hr = E_FAIL;
         goto end_other;
     }
+    knownFoldersStatics = pv;
 
     switch (csidl) {
     case VLC_HOME_DIR:
@@ -161,6 +165,7 @@ static char *config_GetAppDir (void)
     HRESULT hr;
     IStorageFolder *folder = NULL;
 
+    void *pv;
     IApplicationDataStatics *appDataStatics = NULL;
     IApplicationData *appData = NULL;
     static const WCHAR *className = L"Windows.Storage.ApplicationData";
@@ -172,15 +177,16 @@ static char *config_GetAppDir (void)
     if (FAILED(hr))
         goto end_appdata;
 
-    hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, (void**)&appDataStatics);
+    hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, &pv);
 
     if (FAILED(hr))
         goto end_appdata;
 
-    if (!appDataStatics) {
+    if (!pv) {
         hr = E_FAIL;
         goto end_appdata;
     }
+    appDataStatics = pv;
 
     hr = IApplicationDataStatics_get_Current(appDataStatics, &appData);
 
@@ -218,6 +224,7 @@ static char *config_GetCacheDir (void)
 {
     HRESULT hr;
     IStorageFolder *folder = NULL;
+    void *pv;
     IApplicationDataStatics *appDataStatics = NULL;
     IApplicationData *appData = NULL;
     IApplicationData2 *appData2 = NULL;
@@ -230,15 +237,16 @@ static char *config_GetCacheDir (void)
     if (FAILED(hr))
         goto end_appdata;
 
-    hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, (void**)&appDataStatics);
+    hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, &pv);
 
     if (FAILED(hr))
         goto end_appdata;
 
-    if (!appDataStatics) {
+    if (!pv) {
         hr = E_FAIL;
         goto end_appdata;
     }
+    appDataStatics = pv;
 
     hr = IApplicationDataStatics_get_Current(appDataStatics, &appData);
 
@@ -250,11 +258,12 @@ static char *config_GetCacheDir (void)
         goto end_appdata;
     }
 
-    IApplicationData_QueryInterface(appData, &IID_IApplicationData2, (void**)&appData2);
-    if (!appData2) {
+    IApplicationData_QueryInterface(appData, &IID_IApplicationData2, &pv);
+    if (!pv) {
         hr = E_FAIL;
         goto end_appdata;
     }
+    appData2 = pv;
 
     hr = IApplicationData2_get_LocalCacheFolder(appData2, &folder);
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b1e72e112b82c8fa68c9a1c020abe93d3a7f4e17...33015966e6eb6ef0e032cdbc18a706175748e381

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




More information about the vlc-commits mailing list