[lzw] Optimize last commit. * src/lzw/ftzopen.c (ft_lzwstate_get_code): Move check into conditional clause.
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
diff --git a/ChangeLog b/ChangeLog
index a22c693..8aaa78e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2016-08-16 Werner Lemberg <wl@gnu.org>
+ [lzw] Optimize last commit.
+
+ * src/lzw/ftzopen.c (ft_lzwstate_get_code): Move check into
+ conditional clause.
+
+2016-08-16 Werner Lemberg <wl@gnu.org>
+
[lzw] Avoid invalid left shift.
Reported as
diff --git a/src/lzw/ftzopen.c b/src/lzw/ftzopen.c
index ae79fdd..9e66ba9 100644
--- a/src/lzw/ftzopen.c
+++ b/src/lzw/ftzopen.c
@@ -65,16 +65,16 @@
FT_Int result;
- if ( num_bits > LZW_MAX_BITS )
- return -1;
-
if ( state->buf_clear ||
offset >= state->buf_size ||
state->free_ent >= state->free_bits )
{
if ( state->free_ent >= state->free_bits )
{
- state->num_bits = ++num_bits;
+ state->num_bits = ++num_bits;
+ if ( num_bits > LZW_MAX_BITS )
+ return -1;
+
state->free_bits = state->num_bits < state->max_bits
? (FT_UInt)( ( 1UL << num_bits ) - 256 )
: state->max_free + 1;