diff mbox series

[FFmpeg-devel,4/5] avformat/jpegxl_probe: inline various ret < 0 checks

Message ID 20230608142637.45033-5-leo.izen@gmail.com
State New
Headers show
Series JPEG XL Animation Changes | 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

Leo Izen June 8, 2023, 2:26 p.m. UTC
Inlines some ret < 0 checks to look like:
    if ((ret = func()) < 0)
        return ret;

which clarifies code slightly.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
 libavformat/jpegxl_probe.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Anton Khirnov June 9, 2023, 2:32 a.m. UTC | #1
Quoting Leo Izen (2023-06-08 16:26:36)
> Inlines some ret < 0 checks to look like:
>     if ((ret = func()) < 0)
>         return ret;
> 
> which clarifies code slightly.

FWIW I find this variant less readable.
But it's your code, so up to you.
James Almer June 9, 2023, 2:44 a.m. UTC | #2
On 6/8/2023 11:32 PM, Anton Khirnov wrote:
> Quoting Leo Izen (2023-06-08 16:26:36)
>> Inlines some ret < 0 checks to look like:
>>      if ((ret = func()) < 0)
>>          return ret;
>>
>> which clarifies code slightly.
> 
> FWIW I find this variant less readable.
> But it's your code, so up to you.

Agree. It's both less readable and more prone to mistakes.
Michael Niedermayer June 9, 2023, 6:36 p.m. UTC | #3
On Thu, Jun 08, 2023 at 11:44:38PM -0300, James Almer wrote:
> On 6/8/2023 11:32 PM, Anton Khirnov wrote:
> > Quoting Leo Izen (2023-06-08 16:26:36)
> > > Inlines some ret < 0 checks to look like:
> > >      if ((ret = func()) < 0)
> > >          return ret;
> > > 
> > > which clarifies code slightly.
> > 
> > FWIW I find this variant less readable.
> > But it's your code, so up to you.
> 
> Agree. It's both less readable

> and more prone to mistakes.

yes, we had bugs with people misplacing a () in exactly this
style of checking the return

[...]
diff mbox series

Patch

diff --git a/libavformat/jpegxl_probe.c b/libavformat/jpegxl_probe.c
index 88492cb772..b4ab45518a 100644
--- a/libavformat/jpegxl_probe.c
+++ b/libavformat/jpegxl_probe.c
@@ -254,8 +254,7 @@  int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid
     uint64_t extensions;
     int ret;
 
-    ret = init_get_bits8(gb, buf, buflen);
-    if (ret < 0)
+    if ((ret = init_get_bits8(gb, buf, buflen)) < 0)
         return ret;
 
     if (get_bits_long(gb, 16) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
@@ -281,8 +280,7 @@  int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid
 
         /* preview header */
         if (get_bits1(gb)) {
-            ret = jpegxl_read_preview_header(gb);
-            if (ret < 0)
+            if ((ret = jpegxl_read_preview_header(gb)) < 0)
                 return ret;
         }
 
@@ -309,8 +307,7 @@  int ff_jpegxl_verify_codestream_header(const uint8_t *buf, int buflen, int valid
         if (num_extra_channels > 4 && validate_level)
             return -1;
         for (uint32_t i = 0; i < num_extra_channels; i++) {
-            ret = jpegxl_read_extra_channel_info(gb, validate_level);
-            if (ret < 0)
+            if ((ret = jpegxl_read_extra_channel_info(gb, validate_level)) < 0)
                 return ret;
             if (get_bits_left(gb) < 1)
                 return AVERROR_INVALIDDATA;