[sfnt] Signedness fixes.

* src/sfnt/pngshim.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap.c,
src/sfnt/ttkern.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/sfnt/ttsbit.c: Apply.
* src/sfnt/sfdriver.c: Apply.
(sfnt_get_ps_name): Simplify.
This commit is contained in:
Werner Lemberg 2015-02-22 12:03:28 +01:00
parent 3c374c8cda
commit 01f0842eb0
9 changed files with 96 additions and 82 deletions

View File

@ -1,3 +1,13 @@
2015-02-22 Werner Lemberg <wl@gnu.org>
[sfnt] Signedness fixes.
* src/sfnt/pngshim.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap.c,
src/sfnt/ttkern.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/sfnt/ttsbit.c: Apply.
* src/sfnt/sfdriver.c: Apply.
(sfnt_get_ps_name): Simplify.
2015-02-22 Werner Lemberg <wl@gnu.org>
[bdf] Signedness fixes.

View File

@ -37,11 +37,11 @@
/* This code is freely based on cairo-png.c. There's so many ways */
/* to call libpng, and the way cairo does it is defacto standard. */
static int
multiply_alpha( int alpha,
int color )
static unsigned int
multiply_alpha( unsigned int alpha,
unsigned int color )
{
int temp = ( alpha * color ) + 0x80;
unsigned int temp = alpha * color + 0x80;
return ( temp + ( temp >> 8 ) ) >> 8;
@ -82,10 +82,10 @@
blue = multiply_alpha( alpha, blue );
}
base[0] = blue;
base[1] = green;
base[2] = red;
base[3] = alpha;
base[0] = (unsigned char)blue;
base[1] = (unsigned char)green;
base[2] = (unsigned char)red;
base[3] = (unsigned char)alpha;
}
}
}
@ -110,9 +110,9 @@
unsigned int blue = base[2];
base[0] = blue;
base[1] = green;
base[2] = red;
base[0] = (unsigned char)blue;
base[1] = (unsigned char)green;
base[2] = (unsigned char)red;
base[3] = 0xFF;
}
}
@ -258,16 +258,16 @@
if ( populate_map_and_metrics )
{
FT_Long size;
FT_ULong size;
metrics->width = (FT_Int)imgWidth;
metrics->height = (FT_Int)imgHeight;
metrics->width = (FT_UShort)imgWidth;
metrics->height = (FT_UShort)imgHeight;
map->width = metrics->width;
map->rows = metrics->height;
map->pixel_mode = FT_PIXEL_MODE_BGRA;
map->pitch = map->width * 4;
map->pitch = (int)( map->width * 4 );
map->num_grays = 256;
/* reject too large bitmaps similarly to the rasterizer */
@ -278,7 +278,7 @@
}
/* this doesn't overflow: 0x7FFF * 0x7FFF * 4 < 2^32 */
size = map->rows * map->pitch;
size = map->rows * (FT_ULong)map->pitch;
error = ft_glyphslot_alloc_bitmap( slot, size );
if ( error )

View File

@ -266,7 +266,7 @@
{
FT_Stream stream = face->name_table.stream;
FT_String* r = (FT_String*)result;
FT_Byte* p;
FT_Char* p;
if ( FT_STREAM_SEEK( name->stringOffset ) ||
@ -280,11 +280,11 @@
goto Exit;
}
p = (FT_Byte*)stream->cursor;
p = (FT_Char*)stream->cursor;
for ( ; len > 0; len--, p += 2 )
{
if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 )
if ( p[0] == 0 && p[1] >= 32 )
*r++ = p[1];
}
*r = '\0';

View File

@ -580,8 +580,8 @@
table->OrigOffset = sfnt_offset;
/* The offsets must be multiples of 4. */
woff_offset += ( table->CompLength + 3 ) & ~3;
sfnt_offset += ( table->OrigLength + 3 ) & ~3;
woff_offset += ( table->CompLength + 3 ) & ~3U;
sfnt_offset += ( table->OrigLength + 3 ) & ~3U;
}
/*
@ -609,7 +609,7 @@
if ( woff.privOffset )
{
/* ... if it isn't the last block. */
woff_offset = ( woff_offset + 3 ) & ~3;
woff_offset = ( woff_offset + 3 ) & ~3U;
if ( woff.privOffset != woff_offset ||
woff.privOffset + woff.privLength > woff.length )
@ -1431,8 +1431,8 @@
root->ascender = face->horizontal.Ascender;
root->descender = face->horizontal.Descender;
root->height = (FT_Short)( root->ascender - root->descender +
face->horizontal.Line_Gap );
root->height = root->ascender - root->descender +
face->horizontal.Line_Gap;
if ( !( root->ascender || root->descender ) )
{
@ -1443,23 +1443,24 @@
root->ascender = face->os2.sTypoAscender;
root->descender = face->os2.sTypoDescender;
root->height = (FT_Short)( root->ascender - root->descender +
face->os2.sTypoLineGap );
root->height = root->ascender - root->descender +
face->os2.sTypoLineGap;
}
else
{
root->ascender = (FT_Short)face->os2.usWinAscent;
root->descender = -(FT_Short)face->os2.usWinDescent;
root->height = (FT_UShort)( root->ascender - root->descender );
root->height = root->ascender - root->descender;
}
}
}
root->max_advance_width = face->horizontal.advance_Width_Max;
root->max_advance_height = (FT_Short)( face->vertical_info
? face->vertical.advance_Height_Max
: root->height );
root->max_advance_width =
(FT_Short)face->horizontal.advance_Width_Max;
root->max_advance_height =
(FT_Short)( face->vertical_info ? face->vertical.advance_Height_Max
: root->height );
/* See http://www.microsoft.com/OpenType/OTSpec/post.htm -- */
/* Adjust underline position from top edge to centre of */

View File

@ -360,7 +360,7 @@
ids = p - 2 + offset;
if ( ids < glyph_ids || ids + code_count*2 > table + length )
if ( ids < glyph_ids || ids + code_count * 2 > table + length )
FT_INVALID_OFFSET;
/* check glyph IDs */
@ -375,7 +375,7 @@
idx = TT_NEXT_USHORT( p );
if ( idx != 0 )
{
idx = ( idx + delta ) & 0xFFFFU;
idx = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU;
if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
FT_INVALID_GLYPH_ID;
}
@ -472,7 +472,7 @@
idx = TT_PEEK_USHORT( p );
if ( idx != 0 )
result = (FT_UInt)( idx + delta ) & 0xFFFFU;
result = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU;
}
}
return result;
@ -524,7 +524,7 @@
if ( idx != 0 )
{
gindex = ( idx + delta ) & 0xFFFFU;
gindex = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU;
if ( gindex != 0 )
{
result = charcode;
@ -786,7 +786,7 @@
if ( gindex != 0 )
{
gindex = (FT_UInt)( ( gindex + delta ) & 0xFFFFU );
gindex = (FT_UInt)( (FT_Int)gindex + delta ) & 0xFFFFU;
if ( gindex != 0 )
{
cmap->cur_charcode = charcode;
@ -800,7 +800,7 @@
{
do
{
FT_UInt gindex = (FT_UInt)( ( charcode + delta ) & 0xFFFFU );
FT_UInt gindex = (FT_UInt)( (FT_Int)charcode + delta ) & 0xFFFFU;
if ( gindex != 0 )
@ -993,7 +993,7 @@
idx = FT_NEXT_USHORT( p );
if ( idx != 0 )
{
idx = (FT_UInt)( idx + delta ) & 0xFFFFU;
idx = (FT_UInt)( (FT_Int)idx + delta ) & 0xFFFFU;
if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
FT_INVALID_GLYPH_ID;
@ -1090,10 +1090,10 @@
p += offset + ( charcode - start ) * 2;
gindex = TT_PEEK_USHORT( p );
if ( gindex != 0 )
gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU;
gindex = (FT_UInt)( (FT_Int)gindex + delta ) & 0xFFFFU;
}
else
gindex = (FT_UInt)( charcode + delta ) & 0xFFFFU;
gindex = (FT_UInt)( (FT_Int)charcode + delta ) & 0xFFFFU;
break;
}
@ -1294,10 +1294,10 @@
p += offset + ( charcode - start ) * 2;
gindex = TT_PEEK_USHORT( p );
if ( gindex != 0 )
gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU;
gindex = (FT_UInt)( (FT_Int)gindex + delta ) & 0xFFFFU;
}
else
gindex = (FT_UInt)( charcode + delta ) & 0xFFFFU;
gindex = (FT_UInt)( (FT_Int)charcode + delta ) & 0xFFFFU;
break;
}

View File

@ -108,8 +108,8 @@
p_next = p_limit;
/* only use horizontal kerning tables */
if ( ( coverage & ~8 ) != 0x0001 ||
p + 8 > p_limit )
if ( ( coverage & ~8U ) != 0x0001 ||
p + 8 > p_limit )
goto NextTable;
num_pairs = FT_NEXT_USHORT( p );

View File

@ -421,7 +421,7 @@
/* make metrics table length a multiple of 4 */
entry->Length = ( stream->size - entry->Offset ) & ~3;
entry->Length = ( stream->size - entry->Offset ) & ~3U;
FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx"
" (sanitized; original length %08lx)\n",

View File

@ -52,7 +52,7 @@
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
#define MAC_NAME( x ) ( (FT_String*)psnames->macintosh_name( x ) )
#define MAC_NAME( x ) (FT_String*)psnames->macintosh_name( (FT_UInt)(x) )
#else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */
@ -62,7 +62,7 @@
/* table of Mac names. Thus, it is possible to build a version of */
/* FreeType without the Type 1 driver & PSNames module. */
#define MAC_NAME( x ) ( (FT_String*)tt_post_default_names[x] )
#define MAC_NAME( x ) (FT_String*)tt_post_default_names[x]
/* the 258 default Mac PS glyph names; see file `tools/glnames.py' */
@ -155,7 +155,7 @@
static FT_Error
load_format_20( TT_Face face,
FT_Stream stream,
FT_Long post_limit )
FT_ULong post_limit )
{
FT_Memory memory = stream->memory;
FT_Error error;
@ -243,8 +243,8 @@
goto Fail1;
}
if ( (FT_Int)len > post_limit ||
FT_STREAM_POS() > post_limit - (FT_Int)len )
if ( len > post_limit ||
FT_STREAM_POS() > post_limit - len )
{
FT_ERROR(( "load_format_20:"
" exceeding string length (%d),"
@ -307,7 +307,7 @@
static FT_Error
load_format_25( TT_Face face,
FT_Stream stream,
FT_Long post_limit )
FT_ULong post_limit )
{
FT_Memory memory = stream->memory;
FT_Error error;
@ -377,7 +377,7 @@
FT_Error error;
FT_Fixed format;
FT_ULong post_len;
FT_Long post_limit;
FT_ULong post_limit;
/* get a stream for the face's resource */
@ -547,10 +547,7 @@
}
if ( idx < (FT_UInt)table->num_glyphs ) /* paranoid checking */
{
idx += table->offsets[idx];
*PSname = MAC_NAME( idx );
}
*PSname = MAC_NAME( (FT_Int)idx + table->offsets[idx] );
}
/* nothing to do for format == 0x00030000L */

View File

@ -101,10 +101,10 @@
p = face->sbit_table;
version = FT_NEXT_ULONG( p );
version = FT_NEXT_LONG( p );
num_strikes = FT_NEXT_ULONG( p );
if ( ( version & 0xFFFF0000UL ) != 0x00020000UL )
if ( ( (FT_ULong)version & 0xFFFF0000UL ) != 0x00020000UL )
{
error = FT_THROW( Unknown_File_Format );
goto Exit;
@ -273,6 +273,7 @@
FT_UShort ppem, resolution;
TT_HoriHeader *hori;
FT_ULong table_size;
FT_Pos ppem_, upem_; /* to reduce casts */
FT_Error error;
FT_Byte* p;
@ -305,12 +306,15 @@
metrics->x_ppem = ppem;
metrics->y_ppem = ppem;
metrics->ascender = ppem * hori->Ascender * 64 / upem;
metrics->descender = ppem * hori->Descender * 64 / upem;
metrics->height = ppem * ( hori->Ascender -
hori->Descender +
hori->Line_Gap ) * 64 / upem;
metrics->max_advance = ppem * hori->advance_Width_Max * 64 / upem;
ppem_ = (FT_Pos)ppem;
upem_ = (FT_Pos)upem;
metrics->ascender = ppem_ * hori->Ascender * 64 / upem_;
metrics->descender = ppem_ * hori->Descender * 64 / upem_;
metrics->height = ppem_ * ( hori->Ascender -
hori->Descender +
hori->Line_Gap ) * 64 / upem_;
metrics->max_advance = ppem_ * hori->advance_Width_Max * 64 / upem_;
return error;
}
@ -420,7 +424,7 @@
FT_Error error = FT_Err_Ok;
FT_UInt width, height;
FT_Bitmap* map = decoder->bitmap;
FT_Long size;
FT_ULong size;
if ( !decoder->metrics_loaded )
@ -432,38 +436,38 @@
width = decoder->metrics->width;
height = decoder->metrics->height;
map->width = (int)width;
map->rows = (int)height;
map->width = width;
map->rows = height;
switch ( decoder->bit_depth )
{
case 1:
map->pixel_mode = FT_PIXEL_MODE_MONO;
map->pitch = ( map->width + 7 ) >> 3;
map->pitch = (int)( ( map->width + 7 ) >> 3 );
map->num_grays = 2;
break;
case 2:
map->pixel_mode = FT_PIXEL_MODE_GRAY2;
map->pitch = ( map->width + 3 ) >> 2;
map->pitch = (int)( ( map->width + 3 ) >> 2 );
map->num_grays = 4;
break;
case 4:
map->pixel_mode = FT_PIXEL_MODE_GRAY4;
map->pitch = ( map->width + 1 ) >> 1;
map->pitch = (int)( ( map->width + 1 ) >> 1 );
map->num_grays = 16;
break;
case 8:
map->pixel_mode = FT_PIXEL_MODE_GRAY;
map->pitch = map->width;
map->pitch = (int)( map->width );
map->num_grays = 256;
break;
case 32:
map->pixel_mode = FT_PIXEL_MODE_BGRA;
map->pitch = map->width * 4;
map->pitch = (int)( map->width * 4 );
map->num_grays = 256;
break;
@ -472,7 +476,7 @@
goto Exit;
}
size = map->rows * map->pitch;
size = map->rows * (FT_ULong)map->pitch;
/* check that there is no empty image */
if ( size == 0 )
@ -561,7 +565,8 @@
{
FT_Error error = FT_Err_Ok;
FT_Byte* line;
FT_Int bit_height, bit_width, pitch, width, height, line_bits, h;
FT_Int pitch, width, height, line_bits, h;
FT_UInt bit_height, bit_width;
FT_Bitmap* bitmap;
@ -577,8 +582,8 @@
line_bits = width * decoder->bit_depth;
if ( x_pos < 0 || x_pos + width > bit_width ||
y_pos < 0 || y_pos + height > bit_height )
if ( x_pos < 0 || (FT_UInt)( x_pos + width ) > bit_width ||
y_pos < 0 || (FT_UInt)( y_pos + height ) > bit_height )
{
FT_TRACE1(( "tt_sbit_decoder_load_byte_aligned:"
" invalid bitmap dimensions\n" ));
@ -699,7 +704,8 @@
{
FT_Error error = FT_Err_Ok;
FT_Byte* line;
FT_Int bit_height, bit_width, pitch, width, height, line_bits, h, nbits;
FT_Int pitch, width, height, line_bits, h, nbits;
FT_UInt bit_height, bit_width;
FT_Bitmap* bitmap;
FT_UShort rval;
@ -716,8 +722,8 @@
line_bits = width * decoder->bit_depth;
if ( x_pos < 0 || x_pos + width > bit_width ||
y_pos < 0 || y_pos + height > bit_height )
if ( x_pos < 0 || (FT_UInt)( x_pos + width ) > bit_width ||
y_pos < 0 || (FT_UInt)( y_pos + height ) > bit_height )
{
FT_TRACE1(( "tt_sbit_decoder_load_bit_aligned:"
" invalid bitmap dimensions\n" ));
@ -1379,9 +1385,9 @@
metrics->horiBearingX = (FT_Short)originOffsetX;
metrics->horiBearingY = (FT_Short)( -originOffsetY + metrics->height );
metrics->horiAdvance = (FT_Short)( aadvance *
face->root.size->metrics.x_ppem /
face->header.Units_Per_EM );
metrics->horiAdvance = (FT_UShort)( aadvance *
face->root.size->metrics.x_ppem /
face->header.Units_Per_EM );
}
return error;