From e8ed2d621e4182956488ce15c5611472345e63be Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Thu, 1 Aug 2013 12:20:20 +0200 Subject: [PATCH] Another round of cppcheck nitpicks. The call was (from the top-level of the FreeType tree): cppcheck --force \ --enable=all \ -I /usr/include \ -I /usr/local/include \ -I /usr/lib/gcc/i586-suse-linux/4.7/include \ -I include \ -I include/freetype \ -I include/freetype/config \ -I include/freetype/internal \ -DFT2_BUILD_LIBRARY \ . &> cppcheck.log using cppcheck git commit f7e93f99. Note that cppcheck still can't handle `#include FOO' (with `FOO' a macro). */* Improve variable scopes. */* Remove redundant initializations which get overwritten. * src/gxvalid/*: Comment out redundant code or guard it with FT_DEBUG_LEVEL_TRACE. --- ChangeLog | 31 ++++++++++++++++++++- builds/mac/ftmac.c | 1 - src/base/ftglyph.c | 62 ++++++++++++++++++++---------------------- src/base/ftmac.c | 1 - src/base/ftoutln.c | 4 ++- src/base/ftpic.c | 4 +-- src/cff/cf2blues.c | 2 ++ src/cid/cidload.c | 6 ++-- src/gxvalid/gxvcommn.c | 8 ++++++ src/gxvalid/gxvcommn.h | 2 +- src/gxvalid/gxvmort.c | 2 ++ src/gxvalid/gxvmorx2.c | 4 ++- src/pcf/pcfdrivr.c | 25 ++++++++--------- src/pcf/pcfread.c | 2 +- src/pcf/pcfutil.c | 12 ++++---- src/pfr/pfrcmap.c | 10 ++++--- src/pshinter/pshglob.c | 4 +-- src/sfnt/ttcmap.c | 11 +++++--- src/sfnt/ttkern.c | 6 ++-- src/sfnt/ttsbit.c | 6 ++-- src/type1/t1load.c | 4 ++- src/type42/t42objs.c | 2 +- 22 files changed, 128 insertions(+), 81 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8de2ab820..f07d658f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2013-08-01 Werner Lemberg + + Another round of cppcheck nitpicks. + + The call was (from the top-level of the FreeType tree): + + cppcheck --force \ + --enable=all \ + -I /usr/include \ + -I /usr/local/include \ + -I /usr/lib/gcc/i586-suse-linux/4.7/include \ + -I include \ + -I include/freetype \ + -I include/freetype/config \ + -I include/freetype/internal \ + -DFT2_BUILD_LIBRARY \ + . &> cppcheck.log + + using cppcheck git commit f7e93f99. + + Note that cppcheck still can't handle `#include FOO' (with `FOO' a + macro). + + */* Improve variable scopes. + */* Remove redundant initializations which get overwritten. + + * src/gxvalid/*: Comment out redundant code or guard it with + FT_DEBUG_LEVEL_TRACE. + 2013-07-30 Werner Lemberg [autofit] Introduce `writing systems'. @@ -723,7 +752,7 @@ */* Improve variable scopes. */* Remove redundant initializations which get overwritten. - * src/base/ftmac.c ,builds/mac/ftmac.c (count_faces_scalable): + * src/base/ftmac.c, builds/mac/ftmac.c (count_faces_scalable): Remove unused variable. * src/base/ftdbgmem.c (ft_mem_table_destroy): `table' can't be zero. diff --git a/builds/mac/ftmac.c b/builds/mac/ftmac.c index 16d50e87f..40f6bd20c 100644 --- a/builds/mac/ftmac.c +++ b/builds/mac/ftmac.c @@ -1392,7 +1392,6 @@ typedef short ResourceIndex; if ( !pathname ) return FT_THROW( Invalid_Argument ); - error = FT_Err_Ok; *aface = NULL; /* try resourcefork based font: LWFN, FFIL */ diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index 5dd28a8c5..c62b3db0c 100644 --- a/src/base/ftglyph.c +++ b/src/base/ftglyph.c @@ -424,15 +424,16 @@ FT_Matrix* matrix, FT_Vector* delta ) { - const FT_Glyph_Class* clazz; - FT_Error error = FT_Err_Ok; + FT_Error error = FT_Err_Ok; if ( !glyph || !glyph->clazz ) error = FT_THROW( Invalid_Argument ); else { - clazz = glyph->clazz; + const FT_Glyph_Class* clazz = glyph->clazz; + + if ( clazz->glyph_transform ) { /* transform glyph image */ @@ -466,38 +467,33 @@ if ( !glyph || !glyph->clazz ) return; - else + + clazz = glyph->clazz; + if ( !clazz->glyph_bbox ) + return; + + /* retrieve bbox in 26.6 coordinates */ + clazz->glyph_bbox( glyph, acbox ); + + /* perform grid fitting if needed */ + if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT || + bbox_mode == FT_GLYPH_BBOX_PIXELS ) { - clazz = glyph->clazz; - if ( !clazz->glyph_bbox ) - return; - else - { - /* retrieve bbox in 26.6 coordinates */ - clazz->glyph_bbox( glyph, acbox ); - - /* perform grid fitting if needed */ - if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT || - bbox_mode == FT_GLYPH_BBOX_PIXELS ) - { - acbox->xMin = FT_PIX_FLOOR( acbox->xMin ); - acbox->yMin = FT_PIX_FLOOR( acbox->yMin ); - acbox->xMax = FT_PIX_CEIL( acbox->xMax ); - acbox->yMax = FT_PIX_CEIL( acbox->yMax ); - } - - /* convert to integer pixels if needed */ - if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE || - bbox_mode == FT_GLYPH_BBOX_PIXELS ) - { - acbox->xMin >>= 6; - acbox->yMin >>= 6; - acbox->xMax >>= 6; - acbox->yMax >>= 6; - } - } + acbox->xMin = FT_PIX_FLOOR( acbox->xMin ); + acbox->yMin = FT_PIX_FLOOR( acbox->yMin ); + acbox->xMax = FT_PIX_CEIL( acbox->xMax ); + acbox->yMax = FT_PIX_CEIL( acbox->yMax ); + } + + /* convert to integer pixels if needed */ + if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE || + bbox_mode == FT_GLYPH_BBOX_PIXELS ) + { + acbox->xMin >>= 6; + acbox->yMin >>= 6; + acbox->xMax >>= 6; + acbox->yMax >>= 6; } - return; } diff --git a/src/base/ftmac.c b/src/base/ftmac.c index 5b5aae61c..9b49da814 100644 --- a/src/base/ftmac.c +++ b/src/base/ftmac.c @@ -963,7 +963,6 @@ if ( !pathname ) return FT_THROW( Invalid_Argument ); - error = FT_Err_Ok; *aface = NULL; /* try resourcefork based font: LWFN, FFIL */ diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c index 54ca5cdcf..177a4caba 100644 --- a/src/base/ftoutln.c +++ b/src/base/ftoutln.c @@ -576,11 +576,13 @@ { char* p = outline->tags + first; char* q = outline->tags + last; - char swap; while ( p < q ) { + char swap; + + swap = *p; *p = *q; *q = swap; diff --git a/src/base/ftpic.c b/src/base/ftpic.c index 1c8710169..9bd92f785 100644 --- a/src/base/ftpic.c +++ b/src/base/ftpic.c @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services (body). */ /* */ -/* Copyright 2009 by */ +/* Copyright 2009, 2013 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -29,7 +29,7 @@ ft_pic_container_init( FT_Library library ) { FT_PIC_Container* pic_container = &library->pic_container; - FT_Error error = FT_Err_Ok; + FT_Error error; FT_MEM_SET( pic_container, 0, sizeof ( *pic_container ) ); diff --git a/src/cff/cf2blues.c b/src/cff/cf2blues.c index 5b348398a..eec589ef0 100644 --- a/src/cff/cf2blues.c +++ b/src/cff/cf2blues.c @@ -86,11 +86,13 @@ size_t i; CF2_Fixed emBoxBottom, emBoxTop; +#if 0 CF2_Int unitsPerEm = font->unitsPerEm; if ( unitsPerEm == 0 ) unitsPerEm = 1000; +#endif FT_ZERO( blues ); blues->scale = font->innerTransform.d; diff --git a/src/cid/cidload.c b/src/cid/cidload.c index f2a18ea51..46def71b7 100644 --- a/src/cid/cidload.c +++ b/src/cid/cidload.c @@ -150,8 +150,6 @@ cid_parse_font_matrix( CID_Face face, CID_Parser* parser ) { - FT_Matrix* matrix; - FT_Vector* offset; CID_FaceDict dict; FT_Face root = (FT_Face)&face->root; FT_Fixed temp[6]; @@ -160,6 +158,10 @@ if ( parser->num_dict >= 0 && parser->num_dict < face->cid.num_dicts ) { + FT_Matrix* matrix; + FT_Vector* offset; + + dict = face->cid.font_dicts + parser->num_dict; matrix = &dict->font_matrix; offset = &dict->font_offset; diff --git a/src/gxvalid/gxvcommn.c b/src/gxvalid/gxvcommn.c index 2ac80be8c..7af52342b 100644 --- a/src/gxvalid/gxvcommn.c +++ b/src/gxvalid/gxvcommn.c @@ -1288,7 +1288,9 @@ valid ); else { +#if 0 maxState = 1; /* 0:start of text, 1:start of line are predefined */ +#endif maxEntry = 0; } @@ -1621,8 +1623,10 @@ gxv_LookupTable_validate( table + classTable, table + classTable + classTable_length, valid ); +#if 0 if ( valid->subtable_length < classTable_length ) classTable_length = valid->subtable_length; +#endif } else { @@ -1641,7 +1645,9 @@ valid ); else { +#if 0 maxState = 1; /* 0:start of text, 1:start of line are predefined */ +#endif maxEntry = 0; } @@ -1727,6 +1733,7 @@ odtect->range[j].start, odtect->range[j].length ) ) { +#ifdef FT_DEBUG_LEVEL_TRACE if ( odtect->range[i].name || odtect->range[j].name ) GXV_TRACE(( "found overlap between range %d and range %d\n", i, j )); @@ -1734,6 +1741,7 @@ GXV_TRACE(( "found overlap between `%s' and `%s\'\n", odtect->range[i].name, odtect->range[j].name )); +#endif FT_INVALID_OFFSET; } diff --git a/src/gxvalid/gxvcommn.h b/src/gxvalid/gxvcommn.h index 1ff87e442..2f44a7515 100644 --- a/src/gxvalid/gxvcommn.h +++ b/src/gxvalid/gxvcommn.h @@ -318,7 +318,7 @@ FT_BEGIN_HEADER FT_BEGIN_STMNT \ { \ if ( (a) & 3 ) \ - FT_INVALID_OFFSET ; \ + FT_INVALID_OFFSET; \ } \ FT_END_STMNT diff --git a/src/gxvalid/gxvmort.c b/src/gxvalid/gxvmort.c index 5356e67ca..c4d49b32d 100644 --- a/src/gxvalid/gxvmort.c +++ b/src/gxvalid/gxvmort.c @@ -123,6 +123,7 @@ { FT_UNUSED( valid ); +#ifdef FT_DEBUG_LEVEL_TRACE if ( coverage & 0x8000U ) GXV_TRACE(( " this subtable is for vertical text only\n" )); else @@ -141,6 +142,7 @@ if ( coverage & 0x1FF8 ) GXV_TRACE(( " coverage has non-zero bits in reserved area\n" )); +#endif } diff --git a/src/gxvalid/gxvmorx2.c b/src/gxvalid/gxvmorx2.c index 9d2b0bc4a..95b8ea40b 100644 --- a/src/gxvalid/gxvmorx2.c +++ b/src/gxvalid/gxvmorx2.c @@ -5,7 +5,7 @@ /* TrueTypeGX/AAT morx table validation */ /* body for type2 (Ligature Substitution) subtable. */ /* */ -/* Copyright 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */ +/* Copyright 2005, 2013 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -317,7 +317,9 @@ gxv_XStateTable_validate( p, limit, valid ); +#if 0 p += valid->subtable_length; +#endif gxv_morx_subtable_type2_ligatureTable_validate( table, valid ); GXV_EXIT; diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c index df25a645a..9ceff7fef 100644 --- a/src/pcf/pcfdrivr.c +++ b/src/pcf/pcfdrivr.c @@ -218,25 +218,24 @@ THE SOFTWARE. FT_FREE( face->metrics ); /* free properties */ + if ( face->properties ) { - PCF_Property prop; - FT_Int i; + FT_Int i; - if ( face->properties ) + for ( i = 0; i < face->nprops; i++ ) { - for ( i = 0; i < face->nprops; i++ ) - { - prop = &face->properties[i]; + PCF_Property prop = &face->properties[i]; - if ( prop ) - { - FT_FREE( prop->name ); - if ( prop->isString ) - FT_FREE( prop->value.atom ); - } + + if ( prop ) + { + FT_FREE( prop->name ); + if ( prop->isString ) + FT_FREE( prop->value.atom ); } } + FT_FREE( face->properties ); } @@ -264,7 +263,7 @@ THE SOFTWARE. FT_Parameter* params ) { PCF_Face face = (PCF_Face)pcfface; - FT_Error error = FT_Err_Ok; + FT_Error error; FT_UNUSED( num_params ); FT_UNUSED( params ); diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c index 3c1bb7dfa..ee41c5df3 100644 --- a/src/pcf/pcfread.c +++ b/src/pcf/pcfread.c @@ -1096,7 +1096,7 @@ THE SOFTWARE. pcf_load_font( FT_Stream stream, PCF_Face face ) { - FT_Error error = FT_Err_Ok; + FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_Bool hasBDFAccelerators; diff --git a/src/pcf/pcfutil.c b/src/pcf/pcfutil.c index b91274f93..0451ee8de 100644 --- a/src/pcf/pcfutil.c +++ b/src/pcf/pcfutil.c @@ -66,11 +66,11 @@ in this Software without prior written authorization from The Open Group. TwoByteSwap( unsigned char* buf, size_t nbytes ) { - unsigned char c; - - for ( ; nbytes >= 2; nbytes -= 2, buf += 2 ) { + unsigned char c; + + c = buf[0]; buf[0] = buf[1]; buf[1] = c; @@ -85,11 +85,11 @@ in this Software without prior written authorization from The Open Group. FourByteSwap( unsigned char* buf, size_t nbytes ) { - unsigned char c; - - for ( ; nbytes >= 4; nbytes -= 4, buf += 4 ) { + unsigned char c; + + c = buf[0]; buf[0] = buf[3]; buf[3] = c; diff --git a/src/pfr/pfrcmap.c b/src/pfr/pfrcmap.c index 740c433d6..1f05640cc 100644 --- a/src/pfr/pfrcmap.c +++ b/src/pfr/pfrcmap.c @@ -67,14 +67,16 @@ pfr_cmap_char_index( PFR_CMap cmap, FT_UInt32 char_code ) { - FT_UInt min = 0; - FT_UInt max = cmap->num_chars; - FT_UInt mid; - PFR_Char gchar; + FT_UInt min = 0; + FT_UInt max = cmap->num_chars; while ( min < max ) { + PFR_Char gchar; + FT_UInt mid; + + mid = min + ( max - min ) / 2; gchar = cmap->chars + mid; diff --git a/src/pshinter/pshglob.c b/src/pshinter/pshglob.c index 9285efc9e..f75bae451 100644 --- a/src/pshinter/pshglob.c +++ b/src/pshinter/pshglob.c @@ -5,7 +5,7 @@ /* PostScript hinter global hinting management (body). */ /* Inspired by the new auto-hinter module. */ /* */ -/* Copyright 2001-2004, 2006, 2010, 2012 by */ +/* Copyright 2001-2004, 2006, 2010, 2012, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used */ @@ -757,7 +757,7 @@ FT_Fixed x_delta, FT_Fixed y_delta ) { - PSH_Dimension dim = &globals->dimension[0]; + PSH_Dimension dim; dim = &globals->dimension[0]; diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c index 1507202ea..9b7856ba5 100644 --- a/src/sfnt/ttcmap.c +++ b/src/sfnt/ttcmap.c @@ -320,9 +320,8 @@ /* parse sub-headers */ for ( n = 0; n <= max_subs; n++ ) { - FT_UInt first_code, code_count, offset; - FT_Int delta; - FT_Byte* ids; + FT_UInt first_code, code_count, offset; + FT_Int delta; first_code = TT_NEXT_USHORT( p ); @@ -344,6 +343,9 @@ /* check offset */ if ( offset != 0 ) { + FT_Byte* ids; + + ids = p - 2 + offset; if ( ids < glyph_ids || ids + code_count*2 > table + length ) FT_INVALID_OFFSET; @@ -3208,7 +3210,6 @@ { FT_Byte *p = tt_cmap14_find_variant( cmap->data + 6, variantSelector ); - FT_UInt32 *ret; FT_Int i; FT_ULong defOff; FT_ULong nondefOff; @@ -3242,6 +3243,8 @@ FT_Byte* dp; FT_UInt di, ni, k; + FT_UInt32 *ret; + p = cmap->data + nondefOff; dp = cmap->data + defOff; diff --git a/src/sfnt/ttkern.c b/src/sfnt/ttkern.c index 60ee546d7..32c4008b2 100644 --- a/src/sfnt/ttkern.c +++ b/src/sfnt/ttkern.c @@ -5,7 +5,7 @@ /* Load the basic TrueType kerning table. This doesn't handle */ /* kerning data within the GPOS table at the moment. */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 by */ +/* Copyright 1996-2007, 2009, 2010, 2013 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -183,7 +183,7 @@ FT_UInt right_glyph ) { FT_Int result = 0; - FT_UInt count, mask = 1; + FT_UInt count, mask; FT_Byte* p = face->kern_table; FT_Byte* p_limit = p + face->kern_table_size; @@ -196,7 +196,7 @@ count--, mask <<= 1 ) { FT_Byte* base = p; - FT_Byte* next = base; + FT_Byte* next; FT_UInt version = FT_NEXT_USHORT( p ); FT_UInt length = FT_NEXT_USHORT( p ); FT_UInt coverage = FT_NEXT_USHORT( p ); diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c index 7d5685147..8258f79de 100644 --- a/src/sfnt/ttsbit.c +++ b/src/sfnt/ttsbit.c @@ -46,7 +46,7 @@ tt_face_load_sbit( TT_Face face, FT_Stream stream ) { - FT_Error error = FT_Err_Ok; + FT_Error error; FT_ULong table_size; @@ -260,7 +260,7 @@ TT_HoriHeader *hori; FT_ULong table_size; - FT_Error error = FT_Err_Ok; + FT_Error error; FT_Byte* p; @@ -1224,7 +1224,7 @@ FT_Tag graphicType; FT_Int recurse_depth = 0; - FT_Error error = FT_Err_Ok; + FT_Error error; FT_Byte* p; FT_UNUSED( map ); diff --git a/src/type1/t1load.c b/src/type1/t1load.c index 1c834a17b..4b5026bfc 100644 --- a/src/type1/t1load.c +++ b/src/type1/t1load.c @@ -2209,7 +2209,6 @@ if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY ) { FT_Int charcode, idx, min_char, max_char; - FT_Byte* char_name; FT_Byte* glyph_name; @@ -2224,6 +2223,9 @@ charcode = 0; for ( ; charcode < loader.encoding_table.max_elems; charcode++ ) { + FT_Byte* char_name; + + type1->encoding.char_index[charcode] = 0; type1->encoding.char_name [charcode] = (char *)".notdef"; diff --git a/src/type42/t42objs.c b/src/type42/t42objs.c index 18e2c0b62..c9a1c4794 100644 --- a/src/type42/t42objs.c +++ b/src/type42/t42objs.c @@ -507,7 +507,7 @@ FT_Face face = size->face; T42_Face t42face = (T42_Face)face; FT_Size ttsize; - FT_Error error = FT_Err_Ok; + FT_Error error; error = FT_New_Size( t42face->ttf_face, &ttsize );