comparison bitstream.c @ 9905:f3ff182e9ecf libavcodec

Fix potentially unaligned accesses in ff_copy_bits() A pointer should never be assigned a value which may have less than the required alignment of the target type. Compilers may assume pointer values have the required alignment, and emit normal load/store instructions. Unaligned pointers should use a character type or compiler-specific type modifiers.
author mru
date Wed, 01 Jul 2009 17:48:22 +0000
parents 932543edc1d2
children fd9dfd5aa5e9
comparison
equal deleted inserted replaced
9904:efd0c5014ac7 9905:f3ff182e9ecf
76 put_bits(pbc, 8, 0); 76 put_bits(pbc, 8, 0);
77 } 77 }
78 78
79 void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) 79 void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
80 { 80 {
81 const uint16_t *srcw= (const uint16_t*)src;
82 int words= length>>4; 81 int words= length>>4;
83 int bits= length&15; 82 int bits= length&15;
84 int i; 83 int i;
85 84
86 if(length==0) return; 85 if(length==0) return;
87 86
88 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){ 87 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
89 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(&srcw[i])); 88 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
90 }else{ 89 }else{
91 for(i=0; put_bits_count(pb)&31; i++) 90 for(i=0; put_bits_count(pb)&31; i++)
92 put_bits(pb, 8, src[i]); 91 put_bits(pb, 8, src[i]);
93 flush_put_bits(pb); 92 flush_put_bits(pb);
94 memcpy(put_bits_ptr(pb), src+i, 2*words-i); 93 memcpy(put_bits_ptr(pb), src+i, 2*words-i);
95 skip_put_bytes(pb, 2*words-i); 94 skip_put_bytes(pb, 2*words-i);
96 } 95 }
97 96
98 put_bits(pb, bits, AV_RB16(&srcw[words])>>(16-bits)); 97 put_bits(pb, bits, AV_RB16(src + 2*words)>>(16-bits));
99 } 98 }
100 99
101 /* VLC decoding */ 100 /* VLC decoding */
102 101
103 //#define DEBUG_VLC 102 //#define DEBUG_VLC