[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft-devel] Strict compiler warns at gxvmort2.c
From: |
Antoine Leca |
Subject: |
[ft-devel] Strict compiler warns at gxvmort2.c |
Date: |
Tue, 06 Dec 2011 13:45:42 +0100 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.8.1.24) Gecko/20100228 Thunderbird/2.0.0.24 Mnenhy/0.7.6.0 |
Hi Toshiya-san,
Microsoft's compiler bails out while compiling src/gxvalid/gxvalid.c
cl /Za /D_CRT_SECURE_NO_DEPRECATE /Iobjs /I..\freetype2\builds\win32
/I..\freetype2\include /nologo /c /Ox /W3 /WX /DFT2_BUILD_LIBRARY
/DFT_CONFIG_MODULES_H="<ftmodule.h>" /I..\freetype2\src\gxvalid
/Foobjs\gxvalid.obj ..\freetype2\src\gxvalid\gxvalid.c
gxvalid.c
C:\Users\FT\freetype2\src\gxvalid\gxvmort2.c(195) : error C2220: warning
treated as error - no object file generated
C:\Users\FT\freetype2\src\gxvalid\gxvmort2.c(195) : warning C4018: '>' :
signed/unsigned mismatch
mingw32-make.exe: *** [objs/gxvalid.obj] Error 2
A quick look shows this is caused by the combination of
typedef struct GXV_mort_subtable_type2_StateOptRec_
{ /* ... */
FT_UShort ligatureTable;
FT_UShort ligActionTable_length;
and the actual code
FT_ULong offset;
/* ... */
} else if ( offset * 2 >
optdata->ligatureTable + optdata->ligatureTable_length )
The warning is pretty strict but highlights a potential problem on a
16-bit target (the sum can overflow, so being a very big negative, which
will trigger the test in a wrong way.)
I added a cast (to FT_ULong) to avoid the problem.
While I was here, I fixed a number of issues with the printf
specifications in the same area of code; I am not sure this is really
needed since I guess there are a lot of similar mismatches through the
codebase (any comments this about?)
Antoine
diff --git a/src/gxvalid/gxvmort2.c b/src/gxvalid/gxvmort2.c
index 9e08fb7..41bbd7f 100644
--- a/src/gxvalid/gxvmort2.c
+++ b/src/gxvalid/gxvmort2.c
@@ -186,20 +186,23 @@
offset = lig_action & 0x3FFFFFFFUL;
if ( offset * 2 < optdata->ligatureTable )
{
- GXV_TRACE(( "too short offset 0x%08x:"
- " 2 x offset < ligatureTable (%d byte rewind)\n",
- offset, optdata->ligatureTable - offset * 2 ));
+ GXV_TRACE(( "too short offset 0x%08lx:"
+ " 2 x offset < ligatureTable (%ld byte rewind)\n",
+ (unsigned long)offset,
+ optdata->ligatureTable - (long)offset * 2 ));
GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET );
} else if ( offset * 2 >
- optdata->ligatureTable + optdata->ligatureTable_length )
+ (FT_ULong)optdata->ligatureTable +
+ optdata->ligatureTable_length )
{
- GXV_TRACE(( "too long offset 0x%08x:"
+ GXV_TRACE(( "too long offset 0x%08lx:"
" 2 x offset > ligatureTable + ligatureTable_length"
- " (%d byte overrun)\n",
- offset,
- optdata->ligatureTable + optdata->ligatureTable_length
- - offset * 2 ));
+ " (%ld byte overrun)\n",
+ (unsigned long)offset,
+ (long)optdata->ligatureTable
+ + optdata->ligatureTable_length
+ - (long)offset * 2 ));
GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET );
}
- [ft-devel] Strict compiler warns at gxvmort2.c,
Antoine Leca <=