summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2021-09-13 16:29:08 -0400
committerAlexei Podtelezhnikov <apodtele@gmail.com>2021-09-13 16:29:08 -0400
commit731d0b68568541954db753a583e4a5d4ca402fab (patch)
tree6737325fb862e422ba8125865db983738516b207
parent058f3f2d7d137666810612f9753593025e30eeea (diff)
downloadfreetype2-731d0b68568541954db753a583e4a5d4ca402fab.tar.gz
[cff, pshinter] Clean up unsigned counters.
Loops with unsigned decrement can be reliably stopped when the counter wraps around after reaching zero. * src/cff/cffload.c (cff_charset_compute_cids): Use unsigned counter. * src/pshinter/pshalgo.c (psh_hint_table_activate_mask): Ditto. * src/pshinter/pshrec.c (ps_mask_table_merge): Ditto.
-rw-r--r--src/cff/cffload.c8
-rw-r--r--src/pshinter/pshalgo.c7
-rw-r--r--src/pshinter/pshrec.c18
3 files changed, 15 insertions, 18 deletions
diff --git a/src/cff/cffload.c b/src/cff/cffload.c
index eee701d60..76e8fd4a2 100644
--- a/src/cff/cffload.c
+++ b/src/cff/cffload.c
@@ -835,7 +835,6 @@
{
FT_Error error = FT_Err_Ok;
FT_UInt i;
- FT_Long j;
FT_UShort max_cid = 0;
@@ -853,9 +852,10 @@
/* When multiple GIDs map to the same CID, we choose the lowest */
/* GID. This is not described in any spec, but it matches the */
- /* behaviour of recent Acroread versions. */
- for ( j = (FT_Long)num_glyphs - 1; j >= 0; j-- )
- charset->cids[charset->sids[j]] = (FT_UShort)j;
+ /* behaviour of recent Acroread versions. The loop stops when */
+ /* the unsigned index wraps around after reaching zero. */
+ for ( i = num_glyphs - 1; i < num_glyphs; i-- )
+ charset->cids[charset->sids[i]] = (FT_UShort)i;
charset->max_cid = max_cid;
charset->num_glyphs = num_glyphs;
diff --git a/src/pshinter/pshalgo.c b/src/pshinter/pshalgo.c
index e17674b1b..05f91aae4 100644
--- a/src/pshinter/pshalgo.c
+++ b/src/pshinter/pshalgo.c
@@ -305,17 +305,18 @@
/* now, sort the hints; they are guaranteed to not overlap */
/* so we can compare their "org_pos" field directly */
{
- FT_Int i1, i2;
+ FT_UInt i1, i2;
PSH_Hint hint1, hint2;
PSH_Hint* sort = table->sort;
/* a simple bubble sort will do, since in 99% of cases, the hints */
/* will be already sorted -- and the sort will be linear */
- for ( i1 = 1; i1 < (FT_Int)count; i1++ )
+ for ( i1 = 1; i1 < count; i1++ )
{
hint1 = sort[i1];
- for ( i2 = i1 - 1; i2 >= 0; i2-- )
+ /* this loop stops when i2 wraps around after reaching 0 */
+ for ( i2 = i1 - 1; i2 < i1; i2-- )
{
hint2 = sort[i2];
diff --git a/src/pshinter/pshrec.c b/src/pshinter/pshrec.c
index a108734d4..1177c11e6 100644
--- a/src/pshinter/pshrec.c
+++ b/src/pshinter/pshrec.c
@@ -499,23 +499,19 @@
ps_mask_table_merge_all( PS_Mask_Table table,
FT_Memory memory )
{
- FT_Int index1, index2;
+ FT_UInt index1, index2;
FT_Error error = FT_Err_Ok;
- /* both loops go down to 0, thus FT_Int for index1 and index2 */
- for ( index1 = (FT_Int)table->num_masks - 1; index1 > 0; index1-- )
+ /* the inner loop stops when the unsigned index wraps around */
+ /* after reaching 0. */
+ for ( index1 = table->num_masks - 1; index1 > 0; index1-- )
{
- for ( index2 = index1 - 1; index2 >= 0; index2-- )
+ for ( index2 = index1 - 1; index2 < index1; index2-- )
{
- if ( ps_mask_table_test_intersect( table,
- (FT_UInt)index1,
- (FT_UInt)index2 ) )
+ if ( ps_mask_table_test_intersect( table, index1, index2 ) )
{
- error = ps_mask_table_merge( table,
- (FT_UInt)index2,
- (FT_UInt)index1,
- memory );
+ error = ps_mask_table_merge( table, index2, index1, memory );
if ( error )
goto Exit;