diff mbox series

[FFmpeg-devel,09/21] avcodec/smacker: Use unsigned for shift

Message ID 20200801134704.3647-1-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/8] avcodec/smacker: Remove write-only and unused variables
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 1, 2020, 1:46 p.m. UTC
Given that the code currently accepts only 27 bits long Huffman codes,
the shift 1 << (length - 1) with length in 1..28 that is performed when
parsing the tree is safe. Yet if this limit were ever expanded to the
full 32 bits, this shift would be potentially undefined. So simply use
unsigned.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/smacker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paul B Mahol Aug. 1, 2020, 1:57 p.m. UTC | #1
lgtm

On 8/1/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Given that the code currently accepts only 27 bits long Huffman codes,
> the shift 1 << (length - 1) with length in 1..28 that is performed when
> parsing the tree is safe. Yet if this limit were ever expanded to the
> full 32 bits, this shift would be potentially undefined. So simply use
> unsigned.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/smacker.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
> index 9ba70af6f7..e6b163722a 100644
> --- a/libavcodec/smacker.c
> +++ b/libavcodec/smacker.c
> @@ -121,7 +121,7 @@ static int smacker_decode_tree(GetBitContext *gb,
> HuffContext *hc, uint32_t pref
>          r = smacker_decode_tree(gb, hc, prefix, length);
>          if(r)
>              return r;
> -        return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)),
> length);
> +        return smacker_decode_tree(gb, hc, prefix | (1U << (length - 1)),
> length);
>      }
>  }
>
> --
> 2.20.1
>
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 9ba70af6f7..e6b163722a 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -121,7 +121,7 @@  static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t pref
         r = smacker_decode_tree(gb, hc, prefix, length);
         if(r)
             return r;
-        return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
+        return smacker_decode_tree(gb, hc, prefix | (1U << (length - 1)), length);
     }
 }