shithub: freetype+ttf2subf

Download patch

ref: 9b71edb0deb16b68a7944f95f7ef9c9c599e8f02
parent: 4814030bf696bf552c0ee8cb7ea00c62f46ff50e
author: Werner Lemberg <[email protected]>
date: Wed Aug 31 12:29:51 EDT 2005

* src/gxvalid/gxvbsln.c: Fix compiler warnings.
* src/gxvalid/gxvcommn.c: Fix compiler warnings.
(gxv_XEntryTable_validate, gxv_compare_ranges): Remove unused
parameter.  Update all callers.
Improve tracing messages.

Some formatting.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
 2005-08-30  Werner Lemberg  <[email protected]>
 
 	* src/gxvalid/README: Revised.
+	* src/gxvalid/gxvbsln.c: Fix compiler warnings.
+	* src/gxvalid/gxvcommn.c: Fix compiler warnings.
+	(gxv_XEntryTable_validate, gxv_compare_ranges): Remove unused
+	parameter.  Update all callers.
+	Improve tracing messages.
+	Some formatting.
 
 2005-08-29  Werner Lemberg  <[email protected]>
 
--- a/src/gxvalid/Jamfile
+++ b/src/gxvalid/Jamfile
@@ -1,14 +1,26 @@
-# FreeType 2 src/gxvalid Jamfile (c) 2005 suzuki toshiya, Masatake YAMATO and Red Hat K.K.
+# FreeType 2 src/gxvalid Jamfile
 #
+# Copyright 2005 by
+# suzuki toshiya, Masatake YAMATO and Red Hat K.K.
+#
+# This file is part of the FreeType project, and may only be used, modified,
+# and distributed under the terms of the FreeType project license,
+# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
+# indicate that you have read the license and understand and accept it
+# fully.
 
 SubDir  FT2_TOP $(FT2_SRC_DIR) gxvalid ;
 
+
 {
   local  _sources ;
 
   if $(FT2_MULTI)
   {
-    _sources = gxvcommn gxvfeat gxvbsln gxvtrak gxvopbd gxvprop gxvjust gxvmort gxvmort0 gxvmort1 gxvmort2 gxvmort4 gxvmort5 gxvmorx gxvmorx0 gxvmorx1 gxvmorx2 gxvmorx4 gxvmorx5 gxvlcar gxvkern gxvmod ;
+    _sources = gxvcommn gxvfeat  gxvbsln  gxvtrak  gxvopbd  gxvprop
+               gxvmort  gxvmort0 gxvmort1 gxvmort2 gxvmort4 gxvmort5
+               gxvmorx  gxvmorx0 gxvmorx1 gxvmorx2 gxvmorx4 gxvmorx5
+               gxvlcar  gxvkern  gxvmod   gxvjust  ;
   }
   else
   {
--- a/src/gxvalid/gxvalid.h
+++ b/src/gxvalid/gxvalid.h
@@ -16,9 +16,11 @@
 /***************************************************************************/
 
 /***************************************************************************/
+/*                                                                         */
 /* gxvalid is derived from both gxlayout module and otvalid module.        */
-/* Development of gxlayout was support of Information-technology Promotion */
-/* Agency(IPA), Japan.                                                     */
+/* Development of gxlayout is supported by the Information-technology      */
+/* Promotion Agency(IPA), Japan.                                           */
+/*                                                                         */
 /***************************************************************************/
 
 
@@ -75,11 +77,10 @@
                      FT_Validator  valid );
 
   FT_LOCAL( void )
-  gxv_kern_validate_classic
-                   ( FT_Bytes      table,
-                     FT_Face       face,
-                     FT_Int        dialect_flags,
-                     FT_Validator  valid );
+  gxv_kern_validate_classic( FT_Bytes      table,
+                             FT_Face       face,
+                             FT_Int        dialect_flags,
+                             FT_Validator  valid );
 
   FT_LOCAL( void )
   gxv_opbd_validate( FT_Bytes      table,
--- a/src/gxvalid/gxvbsln.c
+++ b/src/gxvalid/gxvbsln.c
@@ -16,9 +16,11 @@
 /***************************************************************************/
 
 /***************************************************************************/
+/*                                                                         */
 /* gxvalid is derived from both gxlayout module and otvalid module.        */
-/* Development of gxlayout was support of Information-technology Promotion */
-/* Agency(IPA), Japan.                                                     */
+/* Development of gxlayout is supported by the Information-technology      */
+/* Promotion Agency(IPA), Japan.                                           */
+/*                                                                         */
 /***************************************************************************/
 
 
@@ -26,7 +28,6 @@
 #include "gxvcommn.h"
 
 
-
   /*************************************************************************/
   /*                                                                       */
   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
@@ -45,9 +46,10 @@
   /*************************************************************************/
   /*************************************************************************/
 
-#define GXV_BSLN_VALUE_COUNT 32
-#define GXV_BSLN_VALUE_EMPTY 0xFFFF
+#define GXV_BSLN_VALUE_COUNT  32
+#define GXV_BSLN_VALUE_EMPTY  0xFFFF
 
+
   typedef struct  GXV_bsln_DataRec_
   {
     FT_Bytes   ctlPoints_p;
@@ -54,9 +56,10 @@
     FT_UShort  defaultBaseline;
 
   } GXV_bsln_DataRec, *GXV_bsln_Data;
-#define GXV_BSLN_DATA(field)  GXV_TABLE_DATA( bsln, field )
 
+#define GXV_BSLN_DATA( field )  GXV_TABLE_DATA( bsln, field )
 
+
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
@@ -70,16 +73,17 @@
                                  GXV_LookupValueDesc  value,
                                  GXV_Validator        valid )
   {
-    FT_UShort   v  = value.u;
+    FT_UShort   v = value.u;
     FT_UShort*  ctlPoints;
 
+    FT_UNUSED( glyph );
 
+
     GXV_NAME_ENTER( " lookup value" );
 
     if ( v >= GXV_BSLN_VALUE_COUNT )
       FT_INVALID_DATA;
 
-
     ctlPoints = (FT_UShort*)GXV_BSLN_DATA( ctlPoints_p );
     if ( ctlPoints && ctlPoints[v] == GXV_BSLN_VALUE_EMPTY )
       FT_INVALID_DATA;
@@ -126,6 +130,7 @@
     FT_UShort            offset;
     GXV_LookupValueDesc  value;
 
+
     offset = base_value.u + ( relative_gindex * sizeof ( FT_UShort ) );
 
     p     = valid->lookuptbl_head + offset;
@@ -137,6 +142,7 @@
     return value;
   }
 
+
   static void
   gxv_bsln_parts_fmt0_validate( FT_Bytes       tables,
                                 FT_Bytes       limit,
@@ -163,6 +169,7 @@
   {
     FT_Bytes  p = tables;
 
+
     GXV_NAME_ENTER( " parts format 1" );
 
     /* deltas */
@@ -185,13 +192,13 @@
                                 FT_Bytes       limit,
                                 GXV_Validator  valid )
   {
-    FT_Bytes      p = tables;
+    FT_Bytes   p = tables;
 
-    FT_UShort     stdGlyph;
-    FT_UShort     ctlPoint;
-    FT_Int        i;
+    FT_UShort  stdGlyph;
+    FT_UShort  ctlPoint;
+    FT_Int     i;
 
-    FT_UShort     defaultBaseline = GXV_BSLN_DATA( defaultBaseline );
+    FT_UShort  defaultBaseline = GXV_BSLN_DATA( defaultBaseline );
 
 
     GXV_NAME_ENTER( "parts format 2" );
@@ -205,7 +212,7 @@
     gxv_glyphid_validate( stdGlyph, valid );
 
     /* Record the position of ctlPoints */
-    GXV_BSLN_DATA( ctlPoints_p) = p;
+    GXV_BSLN_DATA( ctlPoints_p ) = p;
 
     /* ctlPoints */
     for ( i = 0; i < GXV_BSLN_VALUE_COUNT; i++ )
@@ -217,9 +224,7 @@
           FT_INVALID_DATA;
       }
       else
-      {
         gxv_ctlPoint_validate( stdGlyph, (FT_Short)ctlPoint, valid );
-      }
     }
 
     GXV_EXIT;
@@ -264,13 +269,13 @@
                      FT_Face       face,
                      FT_Validator  ftvalid )
   {
-    GXV_ValidatorRec   validrec;
-    GXV_Validator      valid = &validrec;
+    GXV_ValidatorRec  validrec;
+    GXV_Validator     valid = &validrec;
 
-    GXV_bsln_DataRec   bslnrec;
-    GXV_bsln_Data      bsln = &bslnrec;
+    GXV_bsln_DataRec  bslnrec;
+    GXV_bsln_Data     bsln = &bslnrec;
 
-    FT_Bytes  p = table;
+    FT_Bytes  p     = table;
     FT_Bytes  limit = 0;
 
     FT_ULong   version;
@@ -299,11 +304,11 @@
     format          = FT_NEXT_USHORT( p );
     defaultBaseline = FT_NEXT_USHORT( p );
 
-    /* version 1.0 is only defined (1996) */
+    /* only version 1.0 is defined (1996) */
     if ( version != 0x00010000UL )
       FT_INVALID_FORMAT;
 
-    /* format 1, 2, 3 are only defined (1996) */
+    /* only format 1, 2, 3 are defined (1996) */
     GXV_TRACE(( " (format = %d)\n", format ));
     if ( format > 3 )
       FT_INVALID_FORMAT;
@@ -311,7 +316,6 @@
     if ( defaultBaseline > 31 )
       FT_INVALID_FORMAT;
 
-
     bsln->defaultBaseline = defaultBaseline;
 
     fmt_funcs_table[format]( p, limit, valid );
@@ -318,6 +322,7 @@
 
     FT_TRACE4(( "\n" ));
   }
+
 
 /* arch-tag: ebe81143-fdaa-4c68-a4d1-b57227daa3bc
    (do not change this comment) */
--- a/src/gxvalid/gxvcommn.c
+++ b/src/gxvalid/gxvcommn.c
@@ -16,9 +16,11 @@
 /***************************************************************************/
 
 /***************************************************************************/
+/*                                                                         */
 /* gxvalid is derived from both gxlayout module and otvalid module.        */
-/* Development of gxlayout was support of Information-technology Promotion */
-/* Agency(IPA), Japan.                                                     */
+/* Development of gxlayout is supported by the Information-technology      */
+/* Promotion Agency(IPA), Japan.                                           */
+/*                                                                         */
 /***************************************************************************/
 
 
@@ -64,7 +66,7 @@
                                    FT_UShort      limit,
                                    GXV_Validator  valid)
   {
-    FT_UInt    i;
+    FT_UInt  i;
 
 
     for ( i = 0; i < nmemb; i++ )
@@ -74,7 +76,7 @@
       buff[i] = offset[i];
     buff[nmemb] = limit;
 
-    ft_qsort( buff, ( nmemb + 1 ), sizeof(FT_UShort),
+    ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_UShort ),
               ( int(*)(const void*, const void*) )gxv_compare_ushort_offset );
 
     if ( buff[nmemb] > limit )
@@ -82,7 +84,7 @@
 
     for ( i = 0; i < nmemb; i++ )
     {
-      FT_UInt j;
+      FT_UInt  j;
 
 
       for ( j = 0; j < nmemb; j++ )
@@ -89,7 +91,7 @@
         if ( buff[j] == offset[i] )
           break;
 
-      if (j == nmemb)
+      if ( j == nmemb )
         FT_INVALID_OFFSET;
 
       *(length[i]) = buff[j + 1] - buff[j];
@@ -129,7 +131,7 @@
                                   FT_ULong       limit,
                                   GXV_Validator  valid)
   {
-    FT_UInt    i;
+    FT_UInt  i;
 
 
     for ( i = 0; i < nmemb; i++ )
@@ -139,7 +141,7 @@
       buff[i] = offset[i];
     buff[nmemb] = limit;
 
-    ft_qsort( buff, ( nmemb + 1 ), sizeof(FT_ULong),
+    ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_ULong ),
               ( int(*)(const void*, const void*) )gxv_compare_ulong_offset );
 
     if ( buff[nmemb] > limit )
@@ -147,7 +149,7 @@
 
     for ( i = 0; i < nmemb; i++ )
     {
-      FT_UInt j;
+      FT_UInt  j;
 
 
       for ( j = 0; j < nmemb; j++ )
@@ -154,7 +156,7 @@
         if ( buff[j] == offset[i] )
           break;
 
-      if (j == nmemb)
+      if ( j == nmemb )
         FT_INVALID_OFFSET;
 
       *(length[i]) = buff[j + 1] - buff[j];
@@ -191,6 +193,7 @@
     {
       FT_Byte  val;
 
+
       GXV_LIMIT_CHECK( 1 );
       val = FT_NEXT_BYTE( p );
 
@@ -198,7 +201,7 @@
       *max = FT_MAX( *max, val );
     }
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
   }
 
 
@@ -212,7 +215,7 @@
     FT_Bytes  p = table;
 
 
-    *min = 0xFFFF;
+    *min = 0xFFFFU;
     *max = 0x0000;
 
     while ( p < limit )
@@ -219,6 +222,7 @@
     {
       FT_UShort  val;
 
+
       GXV_LIMIT_CHECK( 2 );
       val = FT_NEXT_USHORT( p );
 
@@ -226,7 +230,7 @@
       *max = FT_MAX( *max, val );
     }
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
   }
 
 
@@ -238,13 +242,13 @@
   /*************************************************************************/
   /*************************************************************************/
 
-  typedef struct GXV_BinSrchHeader_
+  typedef struct  GXV_BinSrchHeader_
   {
-    FT_UShort unitSize;
-    FT_UShort nUnits;
-    FT_UShort searchRange;
-    FT_UShort entrySelector;
-    FT_UShort rangeShift;
+    FT_UShort  unitSize;
+    FT_UShort  nUnits;
+    FT_UShort  searchRange;
+    FT_UShort  entrySelector;
+    FT_UShort  rangeShift;
 
   } GXV_BinSrchHeader;
 
@@ -253,9 +257,9 @@
   gxv_BinSrchHeader_check_consistency( GXV_BinSrchHeader*  binSrchHeader,
                                        GXV_Validator       valid )
   {
-    FT_UShort searchRange;
-    FT_UShort entrySelector;
-    FT_UShort rangeShift;
+    FT_UShort  searchRange;
+    FT_UShort  entrySelector;
+    FT_UShort  rangeShift;
 
 
     if ( binSrchHeader->unitSize == 0 )
@@ -266,26 +270,22 @@
       if ( binSrchHeader->searchRange   == 0 &&
            binSrchHeader->entrySelector == 0 &&
            binSrchHeader->rangeShift    == 0 )
-      {
         return;
-      }
       else
-      {
         FT_INVALID_DATA;
-      }
     }
 
     for ( searchRange = 1, entrySelector = 1;
-          ( searchRange * 2 ) <= binSrchHeader->nUnits && searchRange < 0x8000;
+          ( searchRange * 2 ) <= binSrchHeader->nUnits &&
+            searchRange < 0x8000U;
           searchRange *= 2, entrySelector++ )
       ;
 
-    entrySelector --;
-    searchRange *= ( binSrchHeader->unitSize );
-    rangeShift   = ( binSrchHeader->nUnits ) * ( binSrchHeader->unitSize )
-                   - searchRange;
+    entrySelector--;
+    searchRange *= binSrchHeader->unitSize;
+    rangeShift   = binSrchHeader->nUnits * binSrchHeader->unitSize -
+                     searchRange;
 
-
     if ( searchRange   != binSrchHeader->searchRange   ||
          entrySelector != binSrchHeader->entrySelector ||
          rangeShift    != binSrchHeader->rangeShift    )
@@ -302,6 +302,7 @@
                   "rangeShift=%d\n",
                   binSrchHeader->unitSize, binSrchHeader->nUnits,
                   searchRange, entrySelector, rangeShift ));
+
       if ( valid->root->level >= FT_VALIDATE_PARANOID )
         FT_INVALID_DATA;
     }
@@ -314,7 +315,7 @@
    *
    * Essential parameters (unitSize, nUnits) are returned by
    * given pointer, others (searchRange, entrySelector, rangeShift)
-   * can be calculated essential parameters, so they are just
+   * can be calculated by essential parameters, so they are just
    * validated and discarded.
    *
    * However, wrong values in searchRange, entrySelector, rangeShift
@@ -323,7 +324,6 @@
    *   -- suzuki toshiya <[email protected]>
    */
 
-
   FT_LOCAL_DEF( void )
   gxv_BinSrchHeader_validate( FT_Bytes       table,
                               FT_Bytes       limit,
@@ -331,7 +331,7 @@
                               FT_UShort*     nUnits_p,
                               GXV_Validator  valid )
   {
-    FT_Bytes  p = table;
+    FT_Bytes           p = table;
     GXV_BinSrchHeader  binSrchHeader;
 
 
@@ -345,7 +345,7 @@
     else
       binSrchHeader.unitSize = *unitSize_p;
 
-    if ( *nUnits_p == 0)
+    if ( *nUnits_p == 0 )
     {
       GXV_LIMIT_CHECK( 2 );
       binSrchHeader.nUnits = FT_NEXT_USHORT( p );
@@ -365,12 +365,13 @@
       *unitSize_p = binSrchHeader.unitSize;
 
     if ( *nUnits_p == 0 )
-      *nUnits_p   = binSrchHeader.nUnits;
+      *nUnits_p = binSrchHeader.nUnits;
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
     GXV_EXIT;
   }
 
+
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
@@ -379,14 +380,14 @@
   /*************************************************************************/
   /*************************************************************************/
 
-#define GXV_LOOKUP_VALUE_LOAD(P, SIGNSPEC) \
-  ( P += 2, gxv_lookup_value_load( P - 2, SIGNSPEC ) )
+#define GXV_LOOKUP_VALUE_LOAD( P, SIGNSPEC )                   \
+          ( P += 2, gxv_lookup_value_load( P - 2, SIGNSPEC ) )
 
   static GXV_LookupValueDesc
   gxv_lookup_value_load( FT_Bytes  p,
                          int       signspec )
   {
-    GXV_LookupValueDesc v;
+    GXV_LookupValueDesc  v;
 
 
     if ( signspec == GXV_LOOKUPVALUE_UNSIGNED )
@@ -397,26 +398,27 @@
     return v;
   }
 
+
 #define GXV_UNITSIZE_VALIDATE( FORMAT, UNITSIZE, NUNITS, CORRECTSIZE ) \
-          FT_BEGIN_STMNT                                     \
-            if ( UNITSIZE != CORRECTSIZE )                   \
-            {                                                \
-              FT_ERROR(( "unitSize=%d differs from"          \
-                         "expected unitSize=%d"              \
-                         "in LookupTable %s",                \
-                          UNITSIZE, CORRECTSIZE, FORMAT ));  \
-              if ( UNITSIZE != 0 && NUNITS != 0 )            \
-              {                                              \
-                FT_ERROR(( " cannot validate anymore\n" ));  \
-                FT_INVALID_FORMAT;                           \
-              }                                              \
-              else                                           \
-                FT_ERROR(( " forcibly continues\n" ));       \
-            }                                                \
+          FT_BEGIN_STMNT                                               \
+            if ( UNITSIZE != CORRECTSIZE )                             \
+            {                                                          \
+              FT_ERROR(( "unitSize=%d differs from"                    \
+                         "expected unitSize=%d"                        \
+                         "in LookupTable %s",                          \
+                          UNITSIZE, CORRECTSIZE, FORMAT ));            \
+              if ( UNITSIZE != 0 && NUNITS != 0 )                      \
+              {                                                        \
+                FT_ERROR(( " cannot validate anymore\n" ));            \
+                FT_INVALID_FORMAT;                                     \
+              }                                                        \
+              else                                                     \
+                FT_ERROR(( " forcibly continues\n" ));                 \
+            }                                                          \
           FT_END_STMNT
 
 
-  /* ================= Simple Array Format 0 Lookup Table ================= */
+  /* ================= Simple Array Format 0 Lookup Table ================ */
   static void
   gxv_LookupTable_fmt0_validate( FT_Bytes       table,
                                  FT_Bytes       limit,
@@ -435,32 +437,38 @@
     for ( i = 0; i < valid->face->num_glyphs; i++ )
     {
       GXV_LIMIT_CHECK( 2 );
-      if ( p + 2 >= limit ) /* some fonts has too-short fmt0 array */
+      if ( p + 2 >= limit )     /* some fonts have too-short fmt0 array */
       {
-        GXV_TRACE(( "too-short, glyph %d - %d are missing\n",
-                     i, valid->face->num_glyphs ));
+        GXV_TRACE(( "too short, glyphs %d - %d are missing\n",
+                    i, valid->face->num_glyphs ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_GLYPH_ID;
         break;
       }
+
       value = GXV_LOOKUP_VALUE_LOAD( p, valid->lookupval_sign );
       valid->lookupval_func( i, value, valid );
     }
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
     GXV_EXIT;
   }
 
-  /* ================= Segment Single Format 2 Loolup Table =============== */
+
+  /* ================= Segment Single Format 2 Loolup Table ============== */
   /*
-   * Apple spec says: To guarantee that a binary search terminates,
-   *   you must include one or more special "end of search table" values
-   *   at the end of the data to be searched. The number of termination
-   *   values that need to be included is table-specific. The value
-   *   that indicates binary search termination is 0xFFFF.
-   * The problem is that nUnits does not include this end-marker.
-   * It's quite difficult to discriminate following 0xFFFF comes from
+   * Apple spec says:
+   *
+   *   To guarantee that a binary search terminates, you must include one or
+   *   more special `end of search table' values at the end of the data to
+   *   be searched.  The number of termination values that need to be
+   *   included is table-specific.  The value that indicates binary search
+   *   termination is 0xFFFF.
+   *
+   * The problem is that nUnits does not include this end-marker.  It's
+   * quite difficult to discriminate whether the following 0xFFFF comes from
    * the end-marker or some next data.
+   *
    *   -- suzuki toshiya <[email protected]>
    */
   static void
@@ -475,15 +483,14 @@
     {
       if ( p[0] != 0xFF || p[1] != 0xFF || /* lastGlyph */
            p[2] != 0xFF || p[3] != 0xFF )  /* firstGlyph */
-      {
         break;
-      }
       p += unitSize;
     }
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
   }
 
+
   static void
   gxv_LookupTable_fmt2_validate( FT_Bytes       table,
                                  FT_Bytes       limit,
@@ -508,7 +515,6 @@
 
     GXV_UNITSIZE_VALIDATE( "format2", unitSize, nUnits, 6 );
 
-
     for ( unit = 0, gid = 0; unit < nUnits; unit++ )
     {
       GXV_LIMIT_CHECK( 2 + 2 + 2 );
@@ -519,35 +525,32 @@
       gxv_glyphid_validate( firstGlyph, valid );
       gxv_glyphid_validate( lastGlyph, valid );
 
-
       if ( lastGlyph < gid )
       {
         GXV_TRACE(( "reverse ordered segment specification:"
                     " lastGlyph[%d]=%d < lastGlyph[%d]=%d\n",
-                     unit, lastGlyph, unit - 1 , gid ));
+                    unit, lastGlyph, unit - 1 , gid ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_GLYPH_ID;
       }
 
-
       if ( lastGlyph < firstGlyph )
       {
         GXV_TRACE(( "reverse ordered range specification at unit %d:",
                     " lastGlyph %d < firstGlyph %d ",
-                      unit, lastGlyph, firstGlyph ));
+                    unit, lastGlyph, firstGlyph ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_GLYPH_ID;
 
         if ( valid->root->level == FT_VALIDATE_TIGHT )
-          continue; /* ftxvalidator silently skips such entry */
+          continue;     /* ftxvalidator silently skips such an entry */
 
-        FT_TRACE4(( "continue with exchange\n" ));
+        FT_TRACE4(( "continuing with exchanged values\n" ));
         gid        = firstGlyph;
         firstGlyph = lastGlyph;
         lastGlyph  = gid;
       }
 
-
       for ( gid = firstGlyph; gid <= lastGlyph; gid++ )
         valid->lookupval_func( gid, value, valid );
     }
@@ -555,11 +558,12 @@
     gxv_LookupTable_fmt2_skip_endmarkers( p, unitSize, valid );
     p += valid->subtable_length;
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
     GXV_EXIT;
   }
 
-  /* ================= Segment Array Format 4 Lookup Table ================ */
+
+  /* ================= Segment Array Format 4 Lookup Table =============== */
   static void
   gxv_LookupTable_fmt4_validate( FT_Bytes       table,
                                  FT_Bytes       limit,
@@ -594,35 +598,32 @@
       gxv_glyphid_validate( firstGlyph, valid );
       gxv_glyphid_validate( lastGlyph, valid );
 
-
       if ( lastGlyph < gid )
       {
         GXV_TRACE(( "reverse ordered segment specification:"
                     " lastGlyph[%d]=%d < lastGlyph[%d]=%d\n",
-                     unit, lastGlyph, unit - 1 , gid ));
+                    unit, lastGlyph, unit - 1 , gid ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_GLYPH_ID;
       }
 
-
       if ( lastGlyph < firstGlyph )
       {
         GXV_TRACE(( "reverse ordered range specification at unit %d:",
                     " lastGlyph %d < firstGlyph %d ",
-                      unit, lastGlyph, firstGlyph ));
+                    unit, lastGlyph, firstGlyph ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_GLYPH_ID;
 
         if ( valid->root->level == FT_VALIDATE_TIGHT )
-          continue; /* ftxvalidator silently skips such entry */
+          continue; /* ftxvalidator silently skips such an entry */
 
-        FT_TRACE4(( "continue with exchange\n" ));
+        FT_TRACE4(( "continuing with exchanged values\n" ));
         gid        = firstGlyph;
         firstGlyph = lastGlyph;
         lastGlyph  = gid;
       }
 
-
       GXV_LIMIT_CHECK( 2 );
       base_value = GXV_LOOKUP_VALUE_LOAD( p, GXV_LOOKUPVALUE_UNSIGNED );
 
@@ -637,11 +638,12 @@
     gxv_LookupTable_fmt2_skip_endmarkers( p, unitSize, valid );
     p += valid->subtable_length;
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
     GXV_EXIT;
   }
 
-  /* ================= Segment Table Format 6 Lookup Table ================ */
+
+  /* ================= Segment Table Format 6 Lookup Table =============== */
   static void
   gxv_LookupTable_fmt6_skip_endmarkers( FT_Bytes       table,
                                         FT_UShort      unitSize,
@@ -657,9 +659,10 @@
       p += unitSize;
     }
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
   }
 
+
   static void
   gxv_LookupTable_fmt6_validate( FT_Bytes       table,
                                  FT_Bytes       limit,
@@ -689,7 +692,6 @@
       glyph = FT_NEXT_USHORT( p );
       value = GXV_LOOKUP_VALUE_LOAD( p, valid->lookupval_sign );
 
-
       if ( gxv_glyphid_validate( glyph, valid ) )
         GXV_TRACE(( " endmarker found within defined range"
                     " (entry %d < nUnits=%d)\n",
@@ -698,13 +700,12 @@
       if ( prev_glyph > glyph )
       {
         GXV_TRACE(( "current gid 0x%04x < previous gid 0x%04x\n",
-                     glyph, prev_glyph ));
+                    glyph, prev_glyph ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_GLYPH_ID;
       }
       prev_glyph = glyph;
 
-
       valid->lookupval_func( glyph, value, valid );
     }
 
@@ -711,11 +712,12 @@
     gxv_LookupTable_fmt6_skip_endmarkers( p, unitSize, valid );
     p += valid->subtable_length;
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
     GXV_EXIT;
   }
 
-  /* ================= Trimmed Array Format 8 Lookup Table ================ */
+
+  /* ================= Trimmed Array Format 8 Lookup Table =============== */
   static void
   gxv_LookupTable_fmt8_validate( FT_Bytes       table,
                                  FT_Bytes       limit,
@@ -747,7 +749,7 @@
       valid->lookupval_func( firstGlyph + i, value, valid );
     }
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
     GXV_EXIT;
   }
 
@@ -757,10 +759,10 @@
                             FT_Bytes       limit,
                             GXV_Validator  valid )
   {
-    FT_Bytes  p = table;
-    FT_UShort format;
+    FT_Bytes   p = table;
+    FT_UShort  format;
 
-    GXV_Validate_Func fmt_funcs_table [] =
+    GXV_Validate_Func  fmt_funcs_table[] =
     {
       gxv_LookupTable_fmt0_validate, /* 0 */
       NULL,                          /* 1 */
@@ -772,9 +774,10 @@
       NULL,                          /* 7 */
       gxv_LookupTable_fmt8_validate, /* 8 */
     };
-    GXV_Validate_Func func;
 
+    GXV_Validate_Func  func;
 
+
     GXV_NAME_ENTER(" LookupTable" );
 
     /* lookuptbl_head may be used in fmt4 transit function. */
@@ -795,7 +798,7 @@
     func( p, limit, valid );
     p += valid->subtable_length;
 
-    valid->subtable_length = ( p - table );
+    valid->subtable_length = p - table;
 
     GXV_EXIT;
   }
@@ -813,10 +816,10 @@
   gxv_glyphid_validate( FT_UShort      gid,
                         GXV_Validator  valid )
   {
-    FT_Face       face;
+    FT_Face  face;
 
 
-    if ( gid == 0xFFFF )
+    if ( gid == 0xFFFFU )
     {
       GXV_EXIT;
       return 1;
@@ -826,7 +829,7 @@
     if ( face->num_glyphs < gid )
     {
       GXV_TRACE(( " gxv_glyphid_check() gid overflow: num_glyphs %d < %d\n",
-                   face->num_glyphs, gid ));
+                  face->num_glyphs, gid ));
       if ( valid->root->level >= FT_VALIDATE_PARANOID )
         FT_INVALID_GLYPH_ID;
     }
@@ -860,7 +863,7 @@
 
     error = FT_Load_Glyph( face,
                            gid,
-                           FT_LOAD_NO_BITMAP|FT_LOAD_IGNORE_TRANSFORM );
+                           FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM );
     if ( error )
       FT_INVALID_GLYPH_ID;
 
@@ -889,7 +892,7 @@
                          GXV_Validator  valid )
   {
     FT_SfntName  name;
-    FT_Int       i;
+    FT_UInt      i;
     FT_UInt      nnames;
 
 
@@ -898,7 +901,7 @@
     if ( name_index < min_index || max_index < name_index )
       FT_INVALID_FORMAT;
 
-    nnames = FT_Get_Sfnt_Name_Count (valid->face);
+    nnames = FT_Get_Sfnt_Name_Count( valid->face );
     for ( i = 0; i < nnames; i++ )
     {
       if ( FT_Get_Sfnt_Name( valid->face, i, &name ) != FT_Err_Ok )
@@ -931,10 +934,10 @@
   /* -------------------------- Class Table --------------------------- */
 
   /*
-   * highestClass is used to notice how many class are defined in this
-   * Class Subtable. Apple spec does not mention about whether undefined
-   * hole in the class (e.g.: 0-3 are predefined, 4 is unused, 5 is used)
-   * is permitted. At present, hole in defined class is not checked.
+   * highestClass specifies how many classes are defined in this
+   * Class Subtable.  Apple spec does not mention whether undefined
+   * holes in the class (e.g.: 0-3 are predefined, 4 is unused, 5 is used)
+   * are permitted.  At present, holes in a defined class are not checked.
    *   -- suzuki toshiya <[email protected]>
    */
 
@@ -945,15 +948,15 @@
                            FT_Byte*       maxClassID_p,
                            GXV_Validator  valid )
   {
-    FT_Bytes  p     = table;
-    FT_Bytes  limit = table + *length_p;
-    FT_UShort firstGlyph;
-    FT_UShort nGlyphs;
+    FT_Bytes   p     = table;
+    FT_Bytes   limit = table + *length_p;
+    FT_UShort  firstGlyph;
+    FT_UShort  nGlyphs;
 
 
     GXV_NAME_ENTER( "ClassTable" );
 
-    *maxClassID_p = 3;  /* Class 0,2,3 are predefined */
+    *maxClassID_p = 3;  /* Classes 0, 2, and 3 are predefined */
 
     GXV_LIMIT_CHECK( 2 + 2 );
     firstGlyph = FT_NEXT_USHORT( p );
@@ -981,35 +984,37 @@
         classID = FT_NEXT_BYTE( p );
         switch ( classID )
         {
-          /* following class should not be appear in class array */
-          case 0:  /* end of text */
-          case 2:  /* out of bounds */
-          case 3:  /* end of line */
-            FT_INVALID_DATA;
-            break;
+          /* following classes should not appear in class array */
+        case 0:             /* end of text */
+        case 2:             /* out of bounds */
+        case 3:             /* end of line */
+          FT_INVALID_DATA;
+          break;
 
-          case 1:  /* out of bounds */
-          default: /* user-defined: 4 - ( stateSize - 1 ) */
-            if ( classID >= stateSize )
-              FT_INVALID_DATA;   /* assign glyph to undefined state */
-            nGlyphInClass[classID]++;
-            break;
+        case 1:             /* out of bounds */
+        default:            /* user-defined: 4 - ( stateSize - 1 ) */
+          if ( classID >= stateSize )
+            FT_INVALID_DATA;   /* assign glyph to undefined state */
+
+          nGlyphInClass[classID]++;
+          break;
         }
       }
-      *length_p = ( p - table );
+      *length_p = p - table;
 
-
       /* scan max ClassID in use */
       for ( i = 0; i < stateSize; i++ )
-        if ((3 < i) && (nGlyphInClass[i] > 0))
+        if ( ( 3 < i ) && ( nGlyphInClass[i] > 0 ) )
           *maxClassID_p = i;
     }
 
-Out:
-    GXV_TRACE(( "Declared stateSize=0x%02x, Used maxClassID=0x%02x\n", stateSize, *maxClassID_p ));
+  Out:
+    GXV_TRACE(( "Declared stateSize=0x%02x, Used maxClassID=0x%02x\n",
+                stateSize, *maxClassID_p ));
     GXV_EXIT;
   }
 
+
   /* --------------------------- State Array ----------------------------- */
 
   static void
@@ -1030,10 +1035,10 @@
     GXV_NAME_ENTER( "StateArray" );
 
     GXV_TRACE(( "parse %d bytes by stateSize=%d maxClassID=%d\n",
-                       (int)(*length_p), stateSize, (int)(maxClassID) ));
+                (int)(*length_p), stateSize, (int)(maxClassID) ));
 
     /*
-     * 2 states are predefined and must be described in StateArray
+     * 2 states are predefined and must be described in StateArray:
      * state 0 (start of text), 1 (start of line)
      */
     GXV_LIMIT_CHECK( ( 1 + maxClassID ) * 2 );
@@ -1044,7 +1049,7 @@
     /* read if enough to read another state */
     while ( p + ( 1 + maxClassID ) <= limit )
     {
-      (*maxState_p) ++;
+      (*maxState_p)++;
       for ( class = 0; class <= maxClassID; class++ )
       {
         entry = FT_NEXT_BYTE( p );
@@ -1052,13 +1057,14 @@
       }
     }
     GXV_TRACE(( "parsed: maxState=%d, maxEntry=%d\n",
-                         *maxState_p, *maxEntry_p ));
+                *maxState_p, *maxEntry_p ));
 
-    *length_p = ( p - table );
+    *length_p = p - table;
 
     GXV_EXIT;
   }
 
+
   /* --------------------------- Entry Table ----------------------------- */
 
   static void
@@ -1072,11 +1078,12 @@
                            FT_Bytes       statetable_limit,
                            GXV_Validator  valid )
   {
-    FT_Bytes  p = table;
+    FT_Bytes  p     = table;
     FT_Bytes  limit = table + *length_p;
     FT_Byte   entry;
     FT_Byte   state;
     FT_Int    entrySize = 2 + 2 + GXV_GLYPHOFFSET_SIZE( statetable );
+
     GXV_XStateTable_GlyphOffsetDesc  glyphOffset;
 
 
@@ -1089,13 +1096,12 @@
       if ( valid->root->level >= FT_VALIDATE_PARANOID )
         FT_INVALID_TOO_SHORT;
 
-      /* ftxvalidator, FontValidator warns and continues */
-      maxEntry = ( *length_p / entrySize ) - 1;
-      GXV_TRACE(( "too large maxEntry, shrink to %d fit EntryTable length\n",
-                   maxEntry ));
+      /* ftxvalidator and FontValidator both warn and continue */
+      maxEntry = *length_p / entrySize - 1;
+      GXV_TRACE(( "too large maxEntry, shrinking to %d fit EntryTable length\n",
+                  maxEntry ));
     }
 
-
     for ( entry = 0; entry <= maxEntry; entry++ )
     {
       FT_UShort  newState;
@@ -1107,60 +1113,59 @@
       flags    = FT_NEXT_USHORT( p );
 
 
-      if ( newState < stateArray || stateArray + stateArray_length < newState )
+      if ( newState < stateArray                     ||
+           stateArray + stateArray_length < newState )
       {
-        GXV_TRACE(( " newState offset 0x%04x is out of stateArray\n", newState ));
+        GXV_TRACE(( " newState offset 0x%04x is out of stateArray\n",
+                    newState ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_OFFSET;
         continue;
       }
 
-
-      if ( 0 != (( newState - stateArray ) % ( 1 + maxClassID )) )
+      if ( 0 != ( ( newState - stateArray ) % ( 1 + maxClassID ) ) )
       {
         GXV_TRACE(( " newState offset 0x%04x is not aligned to %d-classes\n",
-                                      newState,  1 + maxClassID ));
+                    newState,  1 + maxClassID ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_OFFSET;
         continue;
       }
 
-
       state =  ( newState - stateArray ) / ( 1 + maxClassID );
 
-
       switch ( GXV_GLYPHOFFSET_FMT( statetable ) )
       {
-        case GXV_GLYPHOFFSET_NONE:
-          break;
+      case GXV_GLYPHOFFSET_NONE:
+        break;
 
-        case GXV_GLYPHOFFSET_UCHAR:
-          glyphOffset.uc = FT_NEXT_BYTE( p );
-          break;
+      case GXV_GLYPHOFFSET_UCHAR:
+        glyphOffset.uc = FT_NEXT_BYTE( p );
+        break;
 
-        case GXV_GLYPHOFFSET_CHAR:
-          glyphOffset.c = FT_NEXT_CHAR( p );
-          break;
+      case GXV_GLYPHOFFSET_CHAR:
+        glyphOffset.c = FT_NEXT_CHAR( p );
+        break;
 
-        case GXV_GLYPHOFFSET_USHORT:
-          glyphOffset.u = FT_NEXT_USHORT( p );
-          break;
+      case GXV_GLYPHOFFSET_USHORT:
+        glyphOffset.u = FT_NEXT_USHORT( p );
+        break;
 
-        case GXV_GLYPHOFFSET_SHORT:
-          glyphOffset.s = FT_NEXT_SHORT( p );
-          break;
+      case GXV_GLYPHOFFSET_SHORT:
+        glyphOffset.s = FT_NEXT_SHORT( p );
+        break;
 
-        case GXV_GLYPHOFFSET_ULONG:
-          glyphOffset.ul = FT_NEXT_ULONG( p );
-          break;
+      case GXV_GLYPHOFFSET_ULONG:
+        glyphOffset.ul = FT_NEXT_ULONG( p );
+        break;
 
-        case GXV_GLYPHOFFSET_LONG:
-          glyphOffset.l = FT_NEXT_LONG( p );
-          break;
+      case GXV_GLYPHOFFSET_LONG:
+        glyphOffset.l = FT_NEXT_LONG( p );
+        break;
 
-        default:
-          if ( valid->root->level >= FT_VALIDATE_PARANOID )
-            FT_INVALID_FORMAT;
+      default:
+        if ( valid->root->level >= FT_VALIDATE_PARANOID )
+          FT_INVALID_FORMAT;
       }
 
       if ( NULL != valid->statetable.entry_validate_func )
@@ -1171,11 +1176,12 @@
                                                statetable_limit,
                                                valid );
     }
-    *length_p = ( p - table );
+    *length_p = p - table;
 
     GXV_EXIT;
   }
 
+
   /* =========================== State Table ============================= */
 
   FT_LOCAL_DEF( void )
@@ -1192,6 +1198,7 @@
     FT_UShort*  l[3];
     FT_UShort   buff[4];
 
+
     o[0] = classTable;
     o[1] = stateArray;
     o[2] = entryTable;
@@ -1202,6 +1209,7 @@
     gxv_set_length_by_ushort_offset( o, l, buff, 3, table_size, valid );
   }
 
+
   FT_LOCAL_DEF( void )
   gxv_StateTable_validate( FT_Bytes       table,
                            FT_Bytes       limit,
@@ -1208,11 +1216,13 @@
                            GXV_Validator  valid )
   {
     FT_UShort   stateSize;
-    FT_UShort   classTable;  /* offset to Class(Sub)Table */
-    FT_UShort   stateArray;  /* offset to StateArray */
-    FT_UShort   entryTable;  /* offset to EntryTable */
-#define GXV_STATETABLE_HEADER_SIZE ( 2 + 2 + 2 + 2 )
-#define GXV_STATEHEADER_SIZE GXV_STATETABLE_HEADER_SIZE
+    FT_UShort   classTable;     /* offset to Class(Sub)Table */
+    FT_UShort   stateArray;     /* offset to StateArray */
+    FT_UShort   entryTable;     /* offset to EntryTable */
+
+#define GXV_STATETABLE_HEADER_SIZE  ( 2 + 2 + 2 + 2 )
+#define GXV_STATEHEADER_SIZE        GXV_STATETABLE_HEADER_SIZE
+
     FT_UShort   classTable_length;
     FT_UShort   stateArray_length;
     FT_UShort   entryTable_length;
@@ -1240,13 +1250,12 @@
     GXV_TRACE(( "offset to stateArray=0x%04x\n", stateArray ));
     GXV_TRACE(( "offset to entryTable=0x%04x\n", entryTable ));
 
-    if (stateSize > 0xFF)
+    if ( stateSize > 0xFF )
       FT_INVALID_DATA;
 
     if ( valid->statetable.optdata_load_func != NULL )
       valid->statetable.optdata_load_func( p, limit, valid );
 
-
     if ( valid->statetable.subtable_setup_func != NULL)
       setup_func = valid->statetable.subtable_setup_func;
     else
@@ -1261,10 +1270,9 @@
                 &entryTable_length,
                 valid );
 
-
     GXV_TRACE(( "StateTable Subtables\n" ));
 
-    if (classTable != 0)
+    if ( classTable != 0 )
       gxv_ClassTable_validate( table + classTable,
                                &classTable_length,
                                stateSize,
@@ -1273,7 +1281,7 @@
     else
       maxClassID = stateSize - 1;
 
-    if (stateArray != 0)
+    if ( stateArray != 0 )
       gxv_StateArray_validate( table + stateArray,
                                &stateArray_length,
                                maxClassID,
@@ -1283,14 +1291,14 @@
                                valid );
     else
     {
-      maxState = 1; /* 0:start of text, 1:start of line are predefined */
+      maxState = 1;     /* 0:start of text, 1:start of line are predefined */
       maxEntry = 0;
     }
 
-    if (maxEntry > 0 && entryTable == 0)
+    if ( maxEntry > 0 && entryTable == 0 )
       FT_INVALID_OFFSET;
 
-    if (entryTable != 0)
+    if ( entryTable != 0 )
       gxv_EntryTable_validate( table + entryTable,
                                &entryTable_length,
                                maxEntry,
@@ -1304,8 +1312,9 @@
     GXV_EXIT;
   }
 
-  /* ================ eXtended State Table (for morx) =================== */
 
+  /* ================= eXtended State Table (for morx) =================== */
+
   FT_LOCAL_DEF( void )
   gxv_XStateTable_subtable_setup( FT_ULong       table_size,
                                   FT_ULong       classTable,
@@ -1320,6 +1329,7 @@
     FT_ULong*  l[3];
     FT_ULong   buff[4];
 
+
     o[0] = classTable;
     o[1] = stateArray;
     o[2] = entryTable;
@@ -1336,6 +1346,8 @@
                                       GXV_LookupValueDesc  value,
                                       GXV_Validator        valid )
   {
+    FT_UNUSED( glyph );
+
     if ( value.u >= valid->xstatetable.nClasses )
       FT_INVALID_DATA;
     if ( value.u > valid->xstatetable.maxClassID )
@@ -1380,8 +1392,9 @@
     FT_UShort            offset;
     GXV_LookupValueDesc  value;
 
-    offset = base_value.u + ( relative_gindex * sizeof ( FT_UShort ) );
 
+    offset = base_value.u + relative_gindex * sizeof ( FT_UShort );
+
     p     = valid->lookuptbl_head + offset;
     limit = lookuptbl_limit;
 
@@ -1410,10 +1423,10 @@
     GXV_NAME_ENTER( "XStateArray" );
 
     GXV_TRACE(( "parse % 3d bytes by stateSize=% 3d maxClassID=% 3d\n",
-                       (int)(*length_p), stateSize, (int)(maxClassID) ));
+                (int)(*length_p), stateSize, (int)(maxClassID) ));
 
     /*
-     * 2 states are predefined and must be described
+     * 2 states are predefined and must be described:
      * state 0 (start of text), 1 (start of line)
      */
     GXV_LIMIT_CHECK( ( 1 + maxClassID ) * 2 * 2 );
@@ -1424,7 +1437,7 @@
     /* read if enough to read another state */
     while ( p + ( ( 1 + maxClassID ) * 2 ) <= limit )
     {
-      (*maxState_p) ++;
+      (*maxState_p)++;
       for ( class = 0; class <= maxClassID; class++ )
       {
         entry = FT_NEXT_USHORT( p );
@@ -1432,9 +1445,9 @@
       }
     }
     GXV_TRACE(( "parsed: maxState=%d, maxEntry=%d\n",
-                         *maxState_p, *maxEntry_p ));
+                *maxState_p, *maxEntry_p ));
 
-    *length_p = ( p - table );
+    *length_p = p - table;
 
     GXV_EXIT;
   }
@@ -1444,7 +1457,6 @@
   gxv_XEntryTable_validate( FT_Bytes       table,
                             FT_ULong*      length_p,
                             FT_UShort      maxEntry,
-                            FT_ULong       stateArray,
                             FT_ULong       stateArray_length,
                             FT_UShort      maxClassID,
                             FT_Bytes       xstatetable_table,
@@ -1466,8 +1478,8 @@
 
     for (entry = 0; entry <= maxEntry ; entry++ )
     {
-      FT_UShort  newState_idx;
-      FT_UShort  flags;
+      FT_UShort                        newState_idx;
+      FT_UShort                        flags;
       GXV_XStateTable_GlyphOffsetDesc  glyphOffset;
 
 
@@ -1475,55 +1487,56 @@
       newState_idx = FT_NEXT_USHORT( p );
       flags        = FT_NEXT_USHORT( p );
 
-      if ( stateArray_length < ( newState_idx * 2 ) )
+      if ( stateArray_length < (FT_ULong)( newState_idx * 2 ) )
       {
-        GXV_TRACE(( "  newState index 0x%04x points out of stateArray\n", newState_idx ));
+        GXV_TRACE(( "  newState index 0x%04x points out of stateArray\n",
+                    newState_idx ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_OFFSET;
       }
 
-      state =  newState_idx / ( 1 + maxClassID );
+      state = newState_idx / ( 1 + maxClassID );
       if ( 0 != ( newState_idx % ( 1 + maxClassID ) ) )
       {
-        FT_TRACE4(( "-> new state = %d (supposed) but newState index 0x%04x is not aligned to %d-classes\n",
-                                      state, newState_idx,  1 + maxClassID ));
+        FT_TRACE4(( "-> new state = %d (supposed)\n"
+                    "but newState index 0x%04x is not aligned to %d-classes\n",
+                    state, newState_idx,  1 + maxClassID ));
         if ( valid->root->level >= FT_VALIDATE_PARANOID )
           FT_INVALID_OFFSET;
       }
 
-
       switch ( GXV_GLYPHOFFSET_FMT( xstatetable ) )
       {
-        case GXV_GLYPHOFFSET_NONE:
-          break;
+      case GXV_GLYPHOFFSET_NONE:
+        break;
 
-        case GXV_GLYPHOFFSET_UCHAR:
-          glyphOffset.uc = FT_NEXT_BYTE( p );
-          break;
+      case GXV_GLYPHOFFSET_UCHAR:
+        glyphOffset.uc = FT_NEXT_BYTE( p );
+        break;
 
-        case GXV_GLYPHOFFSET_CHAR:
-          glyphOffset.c = FT_NEXT_CHAR( p );
-          break;
+      case GXV_GLYPHOFFSET_CHAR:
+        glyphOffset.c = FT_NEXT_CHAR( p );
+        break;
 
-        case GXV_GLYPHOFFSET_USHORT:
-          glyphOffset.u = FT_NEXT_USHORT( p );
-          break;
+      case GXV_GLYPHOFFSET_USHORT:
+        glyphOffset.u = FT_NEXT_USHORT( p );
+        break;
 
-        case GXV_GLYPHOFFSET_SHORT:
-          glyphOffset.s = FT_NEXT_SHORT( p );
-          break;
+      case GXV_GLYPHOFFSET_SHORT:
+        glyphOffset.s = FT_NEXT_SHORT( p );
+        break;
 
-        case GXV_GLYPHOFFSET_ULONG:
-          glyphOffset.ul = FT_NEXT_ULONG( p );
-          break;
+      case GXV_GLYPHOFFSET_ULONG:
+        glyphOffset.ul = FT_NEXT_ULONG( p );
+        break;
 
-        case GXV_GLYPHOFFSET_LONG:
-          glyphOffset.l = FT_NEXT_LONG( p );
-          break;
+      case GXV_GLYPHOFFSET_LONG:
+        glyphOffset.l = FT_NEXT_LONG( p );
+        break;
 
-        default:
-          if ( valid->root->level >= FT_VALIDATE_PARANOID )
-            FT_INVALID_FORMAT;
+      default:
+        if ( valid->root->level >= FT_VALIDATE_PARANOID )
+          FT_INVALID_FORMAT;
       }
 
       if ( NULL != valid->xstatetable.entry_validate_func )
@@ -1535,11 +1548,12 @@
                                                 valid );
     }
 
-    *length_p = ( p - table );
+    *length_p = p - table;
 
     GXV_EXIT;
   }
 
+
   FT_LOCAL_DEF( void )
   gxv_XStateTable_validate( FT_Bytes       table,
                             FT_Bytes       limit,
@@ -1546,27 +1560,30 @@
                             GXV_Validator  valid )
   {
     /* StateHeader members */
-    FT_ULong    classTable;  /* offset to Class(Sub)Table */
-    FT_ULong    stateArray;  /* offset to StateArray */
-    FT_ULong    entryTable;  /* offset to EntryTable */
-#define GXV_XSTATETABLE_HEADER_SIZE ( 4 + 4 + 4 + 4 )
-#define GXV_XSTATEHEADER_SIZE GXV_XSTATETABLE_HEADER_SIZE
-    FT_ULong    classTable_length;
-    FT_ULong    stateArray_length;
-    FT_ULong    entryTable_length;
-    FT_UShort   maxState;
-    FT_UShort   maxEntry;
+    FT_ULong   classTable;      /* offset to Class(Sub)Table */
+    FT_ULong   stateArray;      /* offset to StateArray */
+    FT_ULong   entryTable;      /* offset to EntryTable */
 
+#define GXV_XSTATETABLE_HEADER_SIZE  ( 4 + 4 + 4 + 4 )
+#define GXV_XSTATEHEADER_SIZE        GXV_XSTATETABLE_HEADER_SIZE
+
+    FT_ULong   classTable_length;
+    FT_ULong   stateArray_length;
+    FT_ULong   entryTable_length;
+    FT_UShort  maxState;
+    FT_UShort  maxEntry;
+
     GXV_XStateTable_Subtable_Setup_Func  setup_func;
 
-    FT_Bytes    p = table;
+    FT_Bytes   p = table;
 
+
     GXV_NAME_ENTER( "XStateTable" );
 
     GXV_TRACE(( "XStateTable header\n" ));
 
     GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 );
-    valid->xstatetable.nClasses  = FT_NEXT_ULONG( p );
+    valid->xstatetable.nClasses = FT_NEXT_ULONG( p );
     classTable = FT_NEXT_ULONG( p );
     stateArray = FT_NEXT_ULONG( p );
     entryTable = FT_NEXT_ULONG( p );
@@ -1576,7 +1593,7 @@
     GXV_TRACE(( "offset to stateArray=0x%08x\n", stateArray ));
     GXV_TRACE(( "offset to entryTable=0x%08x\n", entryTable ));
 
-    if ( valid->xstatetable.nClasses > 0xFFFF )
+    if ( valid->xstatetable.nClasses > 0xFFFFU )
       FT_INVALID_DATA;
 
     GXV_TRACE(( "StateTable Subtables\n" ));
@@ -1584,8 +1601,7 @@
     if ( valid->xstatetable.optdata_load_func != NULL )
       valid->xstatetable.optdata_load_func( p, limit, valid );
 
-
-    if ( valid->xstatetable.subtable_setup_func != NULL)
+    if ( valid->xstatetable.subtable_setup_func != NULL )
       setup_func = valid->xstatetable.subtable_setup_func;
     else
       setup_func = gxv_XStateTable_subtable_setup;
@@ -1599,13 +1615,12 @@
                 &entryTable_length,
                 valid );
 
-
-    if (classTable != 0)
+    if ( classTable != 0 )
     {
       valid->xstatetable.maxClassID = 0;
-      valid->lookupval_sign   = GXV_LOOKUPVALUE_UNSIGNED;
-      valid->lookupval_func   = gxv_XClassTable_lookupval_validate;
-      valid->lookupfmt4_trans = gxv_XClassTable_lookupfmt4_transit;
+      valid->lookupval_sign         = GXV_LOOKUPVALUE_UNSIGNED;
+      valid->lookupval_func         = gxv_XClassTable_lookupval_validate;
+      valid->lookupfmt4_trans       = gxv_XClassTable_lookupfmt4_transit;
       gxv_LookupTable_validate( table + classTable,
                                 table + classTable + classTable_length,
                                 valid );
@@ -1615,9 +1630,7 @@
     else
       valid->xstatetable.maxClassID = valid->xstatetable.nClasses - 1;
 
-
-    if (stateArray != 0)
-    {
+    if ( stateArray != 0 )
       gxv_XStateArray_validate( table + stateArray,
                                 &stateArray_length,
                                 valid->xstatetable.maxClassID,
@@ -1625,7 +1638,6 @@
                                 &maxState,
                                 &maxEntry,
                                 valid );
-    }
     else
     {
       maxState = 1; /* 0:start of text, 1:start of line are predefined */
@@ -1632,21 +1644,18 @@
       maxEntry = 0;
     }
 
-    if (maxEntry > 0 && entryTable == 0)
+    if ( maxEntry > 0 && entryTable == 0 )
       FT_INVALID_OFFSET;
 
-    if (entryTable != 0)
-    {
+    if ( entryTable != 0 )
       gxv_XEntryTable_validate( table + entryTable,
                                 &entryTable_length,
                                 maxEntry,
-                                stateArray,
                                 stateArray_length,
                                 valid->xstatetable.maxClassID,
                                 table,
                                 limit,
                                 valid );
-    }
 
     GXV_EXIT;
   }
@@ -1661,11 +1670,10 @@
   /*************************************************************************/
 
   FT_LOCAL_DEF( int )
-  gxv_compare_ranges( FT_Bytes       table1_start,
-                      FT_ULong       table1_length,
-                      FT_Bytes       table2_start,
-                      FT_ULong       table2_length,
-                      GXV_Validator  valid )
+  gxv_compare_ranges( FT_Bytes  table1_start,
+                      FT_ULong  table1_length,
+                      FT_Bytes  table2_start,
+                      FT_ULong  table2_length )
   {
     if ( table1_start == table2_start )
     {
@@ -1698,9 +1706,10 @@
     odtect->range[ odtect->nRanges ].start  = start;
     odtect->range[ odtect->nRanges ].length = length;
     odtect->range[ odtect->nRanges ].name   = name;
-    odtect->nRanges ++;
+    odtect->nRanges++;
   }
 
+
   FT_LOCAL_DEF( void )
   gxv_odtect_validate( GXV_odtect_Range  odtect,
                        GXV_Validator     valid   )
@@ -1710,21 +1719,20 @@
 
     GXV_NAME_ENTER( "check overlap among multi ranges" );
 
-    for ( i = 0; i < odtect->nRanges; i ++ )
-      for ( j = 0; j < i; j ++ )
+    for ( i = 0; i < odtect->nRanges; i++ )
+      for ( j = 0; j < i; j++ )
         if ( 0 != gxv_compare_ranges( odtect->range[i].start,
                                       odtect->range[i].length,
                                       odtect->range[j].start,
-                                      odtect->range[j].length,
-                                      valid )                      )
+                                      odtect->range[j].length ) )
         {
           if ( odtect->range[i].name || odtect->range[j].name )
-            GXV_TRACE(( "found overlap between range-%d and range-%d\n",
-                         i, j ));
+            GXV_TRACE(( "found overlap between range %d and range %d\n",
+                        i, j ));
           else
-            GXV_TRACE(( "found overlap between \"%s\" and \"%s\"\n",
-                         odtect->range[i].name,
-                         odtect->range[j].name ));
+            GXV_TRACE(( "found overlap between `%s' and `%s\'\n",
+                        odtect->range[i].name,
+                        odtect->range[j].name ));
           FT_INVALID_OFFSET;
         }