Commit 9bfb737a authored by mru's avatar mru

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.

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@19318 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent d8844b30
...@@ -78,7 +78,6 @@ void ff_put_string(PutBitContext * pbc, const char *s, int terminate_string) ...@@ -78,7 +78,6 @@ void ff_put_string(PutBitContext * pbc, const char *s, int terminate_string)
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
{ {
const uint16_t *srcw= (const uint16_t*)src;
int words= length>>4; int words= length>>4;
int bits= length&15; int bits= length&15;
int i; int i;
...@@ -86,7 +85,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) ...@@ -86,7 +85,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
if(length==0) return; if(length==0) return;
if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){ if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(&srcw[i])); for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
}else{ }else{
for(i=0; put_bits_count(pb)&31; i++) for(i=0; put_bits_count(pb)&31; i++)
put_bits(pb, 8, src[i]); put_bits(pb, 8, src[i]);
...@@ -95,7 +94,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) ...@@ -95,7 +94,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
skip_put_bytes(pb, 2*words-i); skip_put_bytes(pb, 2*words-i);
} }
put_bits(pb, bits, AV_RB16(&srcw[words])>>(16-bits)); put_bits(pb, bits, AV_RB16(src + 2*words)>>(16-bits));
} }
/* VLC decoding */ /* VLC decoding */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment