diff mbox series

[FFmpeg-devel,3/3] avutil/stereo3d: set a sane default value for AVRational fields

Message ID 20240618192034.5027-3-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/3] avutil/ambient_viewing_environment: set a sane default value for AVRational fields | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer June 18, 2024, 7:20 p.m. UTC
Prevent potential divisions by 0 when using them immediately after allocation.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/stereo3d.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer June 18, 2024, 9:13 p.m. UTC | #1
On Tue, Jun 18, 2024 at 04:20:34PM -0300, James Almer wrote:
> Prevent potential divisions by 0 when using them immediately after allocation.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavutil/stereo3d.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

i must have applied the wrong patches locally but this fails to build

CC	libavutil/stereo3d.o
libavutil/stereo3d.c: In function ‘get_defaults’:
libavutil/stereo3d.c:31:47: error: incompatible types when assigning to type ‘int32_t’ {aka ‘int’} from type ‘AVRational’ {aka ‘struct AVRational’}
   31 |     stereo->horizontal_disparity_adjustment = (AVRational) { 0, 1 };
      |                                               ^
make: *** [ffbuild/common.mak:81: libavutil/stereo3d.o] Error 1

thx

[...]
James Almer June 21, 2024, 12:19 p.m. UTC | #2
On 6/18/2024 6:13 PM, Michael Niedermayer wrote:
> On Tue, Jun 18, 2024 at 04:20:34PM -0300, James Almer wrote:
>> Prevent potential divisions by 0 when using them immediately after allocation.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavutil/stereo3d.c | 14 +++++++++++++-
>>   1 file changed, 13 insertions(+), 1 deletion(-)
> 
> i must have applied the wrong patches locally but this fails to build
> 
> CC	libavutil/stereo3d.o
> libavutil/stereo3d.c: In function ‘get_defaults’:
> libavutil/stereo3d.c:31:47: error: incompatible types when assigning to type ‘int32_t’ {aka ‘int’} from type ‘AVRational’ {aka ‘struct AVRational’}

This sounds like you still have Derek's old version in your tree. He has 
since changed it and pushed a different one.

>     31 |     stereo->horizontal_disparity_adjustment = (AVRational) { 0, 1 };
>        |                                               ^
> make: *** [ffbuild/common.mak:81: libavutil/stereo3d.o] Error 1
> 
> thx
> 
> [...]
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer June 21, 2024, 9:11 p.m. UTC | #3
On Fri, Jun 21, 2024 at 09:19:36AM -0300, James Almer wrote:
> On 6/18/2024 6:13 PM, Michael Niedermayer wrote:
> > On Tue, Jun 18, 2024 at 04:20:34PM -0300, James Almer wrote:
> > > Prevent potential divisions by 0 when using them immediately after allocation.
> > > 
> > > Signed-off-by: James Almer <jamrial@gmail.com>
> > > ---
> > >   libavutil/stereo3d.c | 14 +++++++++++++-
> > >   1 file changed, 13 insertions(+), 1 deletion(-)
> > 
> > i must have applied the wrong patches locally but this fails to build
> > 
> > CC	libavutil/stereo3d.o
> > libavutil/stereo3d.c: In function ‘get_defaults’:
> > libavutil/stereo3d.c:31:47: error: incompatible types when assigning to type ‘int32_t’ {aka ‘int’} from type ‘AVRational’ {aka ‘struct AVRational’}
> 
> This sounds like you still have Derek's old version in your tree. He has
> since changed it and pushed a different one.

yes, i realized and fixed that after i sent the mail

thx

[...]
diff mbox series

Patch

diff --git a/libavutil/stereo3d.c b/libavutil/stereo3d.c
index a40a9439bb..19e81e4124 100644
--- a/libavutil/stereo3d.c
+++ b/libavutil/stereo3d.c
@@ -26,9 +26,20 @@ 
 #include "mem.h"
 #include "stereo3d.h"
 
+static void get_defaults(AVStereo3D *stereo)
+{
+    stereo->horizontal_disparity_adjustment = (AVRational) { 0, 1 };
+}
+
 AVStereo3D *av_stereo3d_alloc(void)
 {
-    return av_mallocz(sizeof(AVStereo3D));
+    AVStereo3D *stereo = av_mallocz(sizeof(AVStereo3D));
+    if (!stereo)
+        return NULL;
+
+    get_defaults(stereo);
+
+    return stereo;
 }
 
 AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame)
@@ -40,6 +51,7 @@  AVStereo3D *av_stereo3d_create_side_data(AVFrame *frame)
         return NULL;
 
     memset(side_data->data, 0, sizeof(AVStereo3D));
+    get_defaults((AVStereo3D *)side_data->data);
 
     return (AVStereo3D *)side_data->data;
 }