[vlc-commits] 3d11_shaders: use asprintf() instead of malloc()+sprintf()

Steve Lhomme git at videolan.org
Fri Oct 19 15:35:54 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Oct 19 15:29:04 2018 +0200| [3c375304844ffa64094e7254d2901a70ac16cb6e] | committer: Steve Lhomme

3d11_shaders: use asprintf() instead of malloc()+sprintf()

This will avoid some copy+paste mistakes

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

 modules/video_output/win32/d3d11_shaders.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index f023de481f..c8b5a21423 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -216,17 +216,16 @@ static HRESULT CompileTargetShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool l
                                    const char *psz_adjust_range, const char *psz_move_planes,
                                    ID3D11PixelShader **output)
 {
-    char *shader = malloc(strlen(globPixelShaderDefault) + 32 + strlen(psz_sampler) +
-                          strlen(psz_src_transform) + strlen(psz_primaries_transform) + strlen(psz_display_transform) +
-                          strlen(psz_tone_mapping) + strlen(psz_adjust_range) + strlen(psz_move_planes));
+    char *shader;
+    int allocated = asprintf(&shader, globPixelShaderDefault, legacy_shader ? "" : "Array",
+                             psz_src_transform, psz_display_transform,
+                             psz_primaries_transform, psz_tone_mapping,
+                             psz_adjust_range, psz_move_planes, psz_sampler);
     if (!shader)
     {
         msg_Err(o, "no room for the Pixel Shader");
         return E_OUTOFMEMORY;
     }
-    sprintf(shader, globPixelShaderDefault, legacy_shader ? "" : "Array", psz_src_transform,
-            psz_display_transform, psz_primaries_transform, psz_tone_mapping,
-            psz_adjust_range, psz_move_planes, psz_sampler);
     if (var_InheritInteger(o, "verbose") >= 4)
         msg_Dbg(o, "shader %s", shader);
 #ifndef NDEBUG



More information about the vlc-commits mailing list