diff mbox

[FFmpeg-devel] lswr/rematrix: Remove an aggressive loop optimization / undefined behaviour

Message ID 201702241121.54387.cehoyos@ag.or.at
State Accepted
Commit 353f509ee34823d8567904236c729b308ed94578
Headers show

Commit Message

Carl Eugen Hoyos Feb. 24, 2017, 10:21 a.m. UTC
Hi!

Attached patch fixes a gcc warning (tested 6.3.0).

Please comment, Carl Eugen
From 422e4b2fba6f3c9fbf930908474029cb8088bc46 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Fri, 24 Feb 2017 11:16:26 +0100
Subject: [PATCH] lswr/rematrix: Remove an aggressive loop optimization.

Fixes undefined behaviour and a gcc warning:
libswresample/rematrix.c:376:47: warning: iteration 64 invokes undefined behavior
---
 libswresample/rematrix.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Feb. 24, 2017, 9:24 p.m. UTC | #1
On Fri, Feb 24, 2017 at 11:21:54AM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes a gcc warning (tested 6.3.0).
> 
> Please comment, Carl Eugen

>  rematrix.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 38e092f00db2021f4dfb7677cc1b18bc66808754  0001-lswr-rematrix-Remove-an-aggressive-loop-optimization.patch
> From 422e4b2fba6f3c9fbf930908474029cb8088bc46 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Fri, 24 Feb 2017 11:16:26 +0100
> Subject: [PATCH] lswr/rematrix: Remove an aggressive loop optimization.
> 
> Fixes undefined behaviour and a gcc warning:
> libswresample/rematrix.c:376:47: warning: iteration 64 invokes undefined behavior
> ---
>  libswresample/rematrix.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

should be ok

thx

[...]
Carl Eugen Hoyos Feb. 26, 2017, 11:12 a.m. UTC | #2
2017-02-24 22:24 GMT+01:00 Michael Niedermayer <michael@niedermayer.cc>:
> On Fri, Feb 24, 2017 at 11:21:54AM +0100, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> Attached patch fixes a gcc warning (tested 6.3.0).
>>
>> Please comment, Carl Eugen
>
>>  rematrix.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>> 38e092f00db2021f4dfb7677cc1b18bc66808754  0001-lswr-rematrix-Remove-an-aggressive-loop-optimization.patch
>> From 422e4b2fba6f3c9fbf930908474029cb8088bc46 Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
>> Date: Fri, 24 Feb 2017 11:16:26 +0100
>> Subject: [PATCH] lswr/rematrix: Remove an aggressive loop optimization.
>>
>> Fixes undefined behaviour and a gcc warning:
>> libswresample/rematrix.c:376:47: warning: iteration 64 invokes undefined behavior
>> ---
>>  libswresample/rematrix.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> should be ok

Patch applied.

Thank you, Carl Eugen
diff mbox

Patch

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 4721063..03b9b20 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -371,9 +371,10 @@  av_cold static int auto_matrix(SwrContext *s)
                            s->matrix[1] - s->matrix[0], s->matrix_encoding, s);
 
     if (ret >= 0 && s->int_sample_fmt == AV_SAMPLE_FMT_FLTP) {
-        int i;
-        for (i = 0; i < FF_ARRAY_ELEMS(s->matrix[0])*FF_ARRAY_ELEMS(s->matrix[0]); i++)
-            s->matrix_flt[0][i] = s->matrix[0][i];
+        int i, j;
+        for (i = 0; i < FF_ARRAY_ELEMS(s->matrix[0]); i++)
+            for (j = 0; j < FF_ARRAY_ELEMS(s->matrix[0]); j++)
+                s->matrix_flt[i][j] = s->matrix[i][j];
     }
 
     return ret;