summaryrefslogtreecommitdiffstats
path: root/src/libdca-4-fix-random-crashes-caused-by-invalid-32-bit-shifts.patch
blob: f247802da0b177f4fca33a2021a072ee3c0dbc93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
This file is part of MXE.
See index.html for further information.

Taken from libdca svn: svn://svn.videolan.org/libdca/trunk.

r88 | sam | 2008-07-19 22:26:13 +0000 (Sat, 19 Jul 2008) | 2 lines
  * bitstream.c: fix random crashes caused by invalid 32-bit shifts on 32-bit
    values.

--- libdca.orig/libdca/bitstream.c
+++ libdca/libdca/bitstream.c
@@ -25,6 +25,7 @@
 
 #include "config.h"
 
+#include <stdio.h>
 #include <inttypes.h>
 
 #include "dca.h"
@@ -46,7 +47,7 @@
     state->bigendian_mode = bigendian_mode;
     bitstream_get (state, align * 8);
 }
-#include<stdio.h>
+
 static inline void bitstream_fill_current (dca_state_t * state)
 {
     uint32_t tmp;
@@ -76,12 +77,14 @@
 
 uint32_t dca_bitstream_get_bh (dca_state_t * state, uint32_t num_bits)
 {
-    uint32_t result;
-
-    num_bits -= state->bits_left;
+    uint32_t result = 0;
 
-    result = ((state->current_word << (32 - state->bits_left)) >>
-	      (32 - state->bits_left));
+    if (state->bits_left)
+    {
+	num_bits -= state->bits_left;
+        result = ((state->current_word << (32 - state->bits_left)) >>
+		  (32 - state->bits_left));
+    }
 
     if ( !state->word_mode && num_bits > 28 ) {
         bitstream_fill_current (state);