patch-liba52_bitstream_c 1.8 KB

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