|
| 1 | +Correct type for pointers arithmetic manipulation. |
| 2 | +Fix random crashes caused by invalid 32-bit shifts on 32-bit values (upstream). |
| 3 | + |
| 4 | +from OpenBSD ports |
| 5 | + |
| 6 | +--- a/liba52/bitstream.c Mon Sep 3 19:03:40 2012 |
| 7 | ++++ b/liba52/bitstream.c Mon Sep 3 19:06:39 2012 |
| 8 | +@@ -23,6 +23,7 @@ |
| 9 | + |
| 10 | + #include "config.h" |
| 11 | + |
| 12 | ++#include <stddef.h> |
| 13 | + #include <inttypes.h> |
| 14 | + |
| 15 | + #include "a52.h" |
| 16 | +@@ -33,9 +34,9 @@ |
| 17 | + |
| 18 | + void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf) |
| 19 | + { |
| 20 | +- int align; |
| 21 | ++ ptrdiff_t align; |
| 22 | + |
| 23 | +- align = (long)buf & 3; |
| 24 | ++ align = (ptrdiff_t)buf & 3; |
| 25 | + state->buffer_start = (uint32_t *) (buf - align); |
| 26 | + state->bits_left = 0; |
| 27 | + state->current_word = 0; |
| 28 | +@@ -62,11 +63,14 @@ static inline void bitstream_fill_current (a52_state_t |
| 29 | + |
| 30 | + uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits) |
| 31 | + { |
| 32 | +- uint32_t result; |
| 33 | ++ uint32_t result = 0; |
| 34 | + |
| 35 | +- num_bits -= state->bits_left; |
| 36 | +- result = ((state->current_word << (32 - state->bits_left)) >> |
| 37 | +- (32 - state->bits_left)); |
| 38 | ++ if (state->bits_left) |
| 39 | ++ { |
| 40 | ++ num_bits -= state->bits_left; |
| 41 | ++ result = ((state->current_word << (32 - state->bits_left)) >> |
| 42 | ++ (32 - state->bits_left)); |
| 43 | ++ } |
| 44 | + |
| 45 | + bitstream_fill_current (state); |
| 46 | + |
| 47 | +@@ -80,11 +84,14 @@ uint32_t a52_bitstream_get_bh (a52_state_t * state, ui |
| 48 | + |
| 49 | + int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits) |
| 50 | + { |
| 51 | +- int32_t result; |
| 52 | ++ int32_t result = 0; |
| 53 | + |
| 54 | +- num_bits -= state->bits_left; |
| 55 | +- result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >> |
| 56 | +- (32 - state->bits_left)); |
| 57 | ++ if (state->bits_left) |
| 58 | ++ { |
| 59 | ++ num_bits -= state->bits_left; |
| 60 | ++ result = ((((int32_t)state->current_word) << (32 - state->bits_left)) |
| 61 | ++ >> (32 - state->bits_left)); |
| 62 | ++ } |
| 63 | + |
| 64 | + bitstream_fill_current(state); |
| 65 | + |
0 commit comments