diff mbox

[FFmpeg-devel] lavf/dashdec: Do not use memcpy() to copy a struct

Message ID CAB0OVGpio_ARExRqZx7tEZViViB9OyFsYLbqKNqqxTx3rErHEw@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos April 18, 2018, 7:52 p.m. UTC
2018-04-18 21:10 GMT+02:00, James Almer <jamrial@gmail.com>:
> On 4/18/2018 2:45 PM, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> Attached patch is supposed to fix a warning (and a bug), is this the
>> right and preferred fix?
>>
>> Please comment, Carl Eugen
>>
>>
>> 0001-lavf-dashdec-Do-not-use-memcpy-to-copy-a-struct.patch
>>
>>
>> From cf7d2aefc1a3b3a2e9f578ede43906ed6ee96bfd Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
>> Date: Wed, 18 Apr 2018 19:42:57 +0200
>> Subject: [PATCH] lavf/dashdec: Do not use memcpy() to copy a struct.
>>
>> Fixes a warning:
>> libavformat/dashdec.c:1900:65: warning: argument to 'sizeof' in 'memcpy'
>> call is the same pointer type 'struct fragment *' as the destination;
>> expected 'struct fragment' or an explicit length
>> ---
>>  libavformat/dashdec.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
>> index 6304ad9..917fb54 100644
>> --- a/libavformat/dashdec.c
>> +++ b/libavformat/dashdec.c
>> @@ -1897,7 +1897,7 @@ static int init_section_compare_audio(DASHContext
>> *c)
>>
>>  static void copy_init_section(struct representation *rep_dest, struct
>> representation *rep_src)
>>  {
>> -    memcpy(rep_dest->init_section, rep_src->init_section,
>> sizeof(rep_src->init_section));
>> +    rep_dest->init_section = rep_src->init_section;
>
> This would only copy the pointer. The fact memcpy was used here makes me
> think the intention was to copy the contents of the struct, so something
> like
>
> *rep_dest->init_section = *rep_src->init_section;

Of course.

New patch attached, Carl Eugen

Comments

wm4 April 18, 2018, 8 p.m. UTC | #1
On Wed, 18 Apr 2018 21:52:45 +0200
Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> From cf7d2aefc1a3b3a2e9f578ede43906ed6ee96bfd Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
> Date: Wed, 18 Apr 2018 19:42:57 +0200
> Subject: [PATCH] lavf/dashdec: Do not use memcpy() to copy a struct.
> 
> Fixes a warning:
> libavformat/dashdec.c:1900:65: warning: argument to 'sizeof' in 'memcpy' call is the same pointer type 'struct fragment *' as the destination; expected 'struct fragment' or an explicit length
> ---
>  libavformat/dashdec.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 6304ad9..917fb54 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -1897,7 +1897,7 @@ static int init_section_compare_audio(DASHContext *c)
>  
>  static void copy_init_section(struct representation *rep_dest, struct representation *rep_src)
>  {
> -    memcpy(rep_dest->init_section, rep_src->init_section, sizeof(rep_src->init_section));
> +    *rep_dest->init_section = *rep_src->init_section;
>      rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size);
>      memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf, rep_src->init_sec_data_len);
>      rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size;

Probably not complete, because it doesn't copy the url field.
diff mbox

Patch

From cf7d2aefc1a3b3a2e9f578ede43906ed6ee96bfd Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Wed, 18 Apr 2018 19:42:57 +0200
Subject: [PATCH] lavf/dashdec: Do not use memcpy() to copy a struct.

Fixes a warning:
libavformat/dashdec.c:1900:65: warning: argument to 'sizeof' in 'memcpy' call is the same pointer type 'struct fragment *' as the destination; expected 'struct fragment' or an explicit length
---
 libavformat/dashdec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 6304ad9..917fb54 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -1897,7 +1897,7 @@  static int init_section_compare_audio(DASHContext *c)
 
 static void copy_init_section(struct representation *rep_dest, struct representation *rep_src)
 {
-    memcpy(rep_dest->init_section, rep_src->init_section, sizeof(rep_src->init_section));
+    *rep_dest->init_section = *rep_src->init_section;
     rep_dest->init_sec_buf = av_mallocz(rep_src->init_sec_buf_size);
     memcpy(rep_dest->init_sec_buf, rep_src->init_sec_buf, rep_src->init_sec_data_len);
     rep_dest->init_sec_buf_size = rep_src->init_sec_buf_size;
-- 
1.7.10.4