From ed0e2e76d849b72964abfba95390788cf992bfcf Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Tue, 8 Feb 2022 16:35:14 -0500 Subject: [PATCH] [pshinter] Fix mask merging. We forgot to update the number of bits when merging a larger mask into a smaller one. This fix might have rendering effects. * src/pshinter/pshrec.c (ps_mask_table_merge): Inherit the number of bits from a larger mask. There is no need to zero unused bits, already zeroed during allocation. (ps_mask_clear_bit): Removed. (ps_mask_ensure): Minor. --- src/pshinter/pshrec.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/pshinter/pshrec.c b/src/pshinter/pshrec.c index eae6e401b..66c90c275 100644 --- a/src/pshinter/pshrec.c +++ b/src/pshinter/pshrec.c @@ -131,14 +131,15 @@ FT_UInt count, FT_Memory memory ) { - FT_UInt old_max = ( mask->max_bits + 7 ) >> 3; - FT_UInt new_max = ( count + 7 ) >> 3; + FT_UInt old_max = mask->max_bits >> 3; + FT_UInt new_max = ( count + 7 ) >> 3; FT_Error error = FT_Err_Ok; if ( new_max > old_max ) { new_max = FT_PAD_CEIL( new_max, 8 ); + /* added bytes are zeroed here */ if ( !FT_RENEW_ARRAY( mask->bytes, old_max, new_max ) ) mask->max_bits = new_max * 8; } @@ -158,22 +159,6 @@ } - /* clear a given bit */ - static void - ps_mask_clear_bit( PS_Mask mask, - FT_UInt idx ) - { - FT_Byte* p; - - - if ( idx >= mask->num_bits ) - return; - - p = mask->bytes + ( idx >> 3 ); - p[0] = (FT_Byte)( p[0] & ~( 0x80 >> ( idx & 7 ) ) ); - } - - /* set a given bit, possibly grow the mask */ static FT_Error ps_mask_set_bit( PS_Mask mask, @@ -432,15 +417,14 @@ /* if "count2" is greater than "count1", we need to grow the */ - /* first bitset, and clear the highest bits */ + /* first bitset */ if ( count2 > count1 ) { error = ps_mask_ensure( mask1, count2, memory ); if ( error ) goto Exit; - for ( pos = count1; pos < count2; pos++ ) - ps_mask_clear_bit( mask1, pos ); + mask1->num_bits = count2; } /* merge (unite) the bitsets */