Lines 32-39
Link Here
|
32 |
} |
32 |
} |
33 |
|
33 |
|
34 |
/* count */ |
34 |
/* count */ |
35 |
for (i = 0; i < nchar; i++) |
35 |
for (i = 0; i < nchar; i++) { |
36 |
count[bitlen[i]]++; |
36 |
if (bitlen[i] > 16) { |
|
|
37 |
error("Bad table (case a)"); |
38 |
exit(1); |
39 |
} |
40 |
else |
41 |
count[bitlen[i]]++; |
42 |
} |
37 |
|
43 |
|
38 |
/* calculate first code */ |
44 |
/* calculate first code */ |
39 |
total = 0; |
45 |
total = 0; |
Lines 41-48
Link Here
|
41 |
start[i] = total; |
47 |
start[i] = total; |
42 |
total += weight[i] * count[i]; |
48 |
total += weight[i] * count[i]; |
43 |
} |
49 |
} |
44 |
if ((total & 0xffff) != 0) |
50 |
if ((total & 0xffff) != 0 || tablebits > 16) { /* 16 for weight below */ |
45 |
error("make_table(): Bad table (5)"); |
51 |
error("make_table(): Bad table (5)"); |
|
|
52 |
exit(1); |
53 |
} |
46 |
|
54 |
|
47 |
/* shift data for make table. */ |
55 |
/* shift data for make table. */ |
48 |
m = 16 - tablebits; |
56 |
m = 16 - tablebits; |
Lines 53-59
Link Here
|
53 |
|
61 |
|
54 |
/* initialize */ |
62 |
/* initialize */ |
55 |
j = start[tablebits + 1] >> m; |
63 |
j = start[tablebits + 1] >> m; |
56 |
k = 1 << tablebits; |
64 |
k = MIN(1 << tablebits, 4096); |
57 |
if (j != 0) |
65 |
if (j != 0) |
58 |
for (i = j; i < k; i++) |
66 |
for (i = j; i < k; i++) |
59 |
table[i] = 0; |
67 |
table[i] = 0; |
Lines 66-77
Link Here
|
66 |
l = start[k] + weight[k]; |
74 |
l = start[k] + weight[k]; |
67 |
if (k <= tablebits) { |
75 |
if (k <= tablebits) { |
68 |
/* code in table */ |
76 |
/* code in table */ |
|
|
77 |
l = MIN(l, 4096); |
69 |
for (i = start[k]; i < l; i++) |
78 |
for (i = start[k]; i < l; i++) |
70 |
table[i] = j; |
79 |
table[i] = j; |
71 |
} |
80 |
} |
72 |
else { |
81 |
else { |
73 |
/* code not in table */ |
82 |
/* code not in table */ |
74 |
p = &table[(i = start[k]) >> m]; |
83 |
i = start[k]; |
|
|
84 |
if ((i >> m) > 4096) { |
85 |
error("Bad table"); |
86 |
exit(1); |
87 |
} |
88 |
p = &table[i >> m]; |
75 |
i <<= tablebits; |
89 |
i <<= tablebits; |
76 |
n = k - tablebits; |
90 |
n = k - tablebits; |
77 |
/* make tree (n length) */ |
91 |
/* make tree (n length) */ |