On Thu, Apr 28, 2011 at 5:08 AM, Måns Rullgård <m...@mansr.com> wrote: > Aℓex Converse <aconve...@google.com> writes: > >> From ae62aa2fca3b2cf45a98dc2f9777065bcb452797 Mon Sep 17 00:00:00 2001 >> From: Alex Converse <aconve...@google.com> >> Date: Tue, 26 Apr 2011 09:08:26 -0700 >> Subject: [PATCH 3/4] bitstream: Properly promote av_reverse values before >> shifting. >> MIME-Version: 1.0 >> Content-Type: multipart/mixed; boundary="------------1" >> >> This is a multi-part message in MIME format. >> --------------1 >> Content-Type: text/plain; charset=UTF-8; format=fixed >> Content-Transfer-Encoding: 8bit >> >> --- >> libavcodec/bitstream.c | 8 ++++---- >> 1 files changed, 4 insertions(+), 4 deletions(-) >> >> --------------1 >> Content-Type: text/x-patch; >> name="0003-bitstream-Properly-promote-av_reverse-values-before-.patch" >> Content-Transfer-Encoding: 8bit >> Content-Disposition: attachment; >> filename="0003-bitstream-Properly-promote-av_reverse-values-before-.patch" >> >> diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c >> index 329ec95..14c3eaa 100644 >> --- a/libavcodec/bitstream.c >> +++ b/libavcodec/bitstream.c >> @@ -118,10 +118,10 @@ static int alloc_table(VLC *vlc, int size, int >> use_static) >> } >> >> static av_always_inline uint32_t bitswap_32(uint32_t x) { >> - return av_reverse[x&0xFF]<<24 >> - | av_reverse[(x>>8)&0xFF]<<16 >> - | av_reverse[(x>>16)&0xFF]<<8 >> - | av_reverse[x>>24]; >> + return (uint32_t)av_reverse[x&0xFF]<<24 >> + | (uint32_t)av_reverse[(x>>8)&0xFF]<<16 >> + | (uint32_t)av_reverse[(x>>16)&0xFF]<<8 >> + | (uint32_t)av_reverse[x>>24]; >> } > > The integer promotions already do this. >
We are operating on uint8_t and int. The promoted the result is an int because the full range of uint8_t can fit in int. Consider the following program: #include <stdio.h> #include <stdint.h> static const uint8_t arr[] = { 128, 129, 130}; int main() { int x; typeof(x) y; printf(" int32_t %d\n", __builtin_types_compatible_p(typeof(arr[1]<<24), int32_t)); printf("uint32_t %d\n", __builtin_types_compatible_p(typeof(arr[1]<<24), uint32_t)); return 0; } _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel