[FFmpeg-devel] [PATCH] Revert "lavc/v4l2_m2m_enc: Add missing braces around initializers."

Mark Thompson sw at jkqxz.net
Sat Oct 27 22:10:20 EEST 2018


On 27/10/18 19:56, James Almer wrote:
> On 10/27/2018 3:50 PM, Mark Thompson wrote:
>> This reverts commit 6dbb64fdccafe846aaec75d3784f7ad49d8af5df.
>>
>> The additional braces cause build errors with Linux headers earlier
>> than 4.5 because the first element of the structure was not originally
>> a union.
>> ---
>> Not sure what compiler was warning about these, but it's definitely incorrect for it to do so.  Maybe an old gcc?  Recent gcc should have this fixed - see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119>.
> 
> Clang seems to do it as well. See
> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-October/235632.html
> 
> You could initialize it setting the three fields directly, or use a memset.

Looks like the incorrect warning has been fixed in recent clang too: <https://reviews.llvm.org/D28148>.

If you want to avoid the warning with older broken compilers then maybe we could do some sort of test to disable it?

E.g. try to compile

struct { union { int a; char b } c; int d; } = { 0 }

with "-Werror -Wmissing-braces" and then with "-Werror -Wno-missing-braces" and pass the option if the second succeeds where the first does not.

- Mark

>>
>>
>>  libavcodec/v4l2_m2m_enc.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
>> index 636e1a96dd..4c9ea1fd92 100644
>> --- a/libavcodec/v4l2_m2m_enc.c
>> +++ b/libavcodec/v4l2_m2m_enc.c
>> @@ -48,7 +48,7 @@ static inline void v4l2_set_timeperframe(V4L2m2mContext *s, unsigned int num, un
>>  
>>  static inline void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int value, const char *name)
>>  {
>> -    struct v4l2_ext_controls ctrls = { { 0 } };
>> +    struct v4l2_ext_controls ctrls = { 0 };
>>      struct v4l2_ext_control ctrl = { 0 };
>>  
>>      /* set ctrls */
>> @@ -68,7 +68,7 @@ static inline void v4l2_set_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed
>>  
>>  static inline int v4l2_get_ext_ctrl(V4L2m2mContext *s, unsigned int id, signed int *value, const char *name)
>>  {
>> -    struct v4l2_ext_controls ctrls = { { 0 } };
>> +    struct v4l2_ext_controls ctrls = { 0 };
>>      struct v4l2_ext_control ctrl = { 0 };
>>      int ret;
>>  
>>


More information about the ffmpeg-devel mailing list