File: | base/ftpatent.c |
Location: | line 134, column 12 |
Description: | Pass-by-value argument in function call is undefined |
1 | /***************************************************************************/ | ||||
2 | /* */ | ||||
3 | /* ftpatent.c */ | ||||
4 | /* */ | ||||
5 | /* FreeType API for checking patented TrueType bytecode instructions */ | ||||
6 | /* (body). */ | ||||
7 | /* */ | ||||
8 | /* Copyright 2007, 2008 by David Turner. */ | ||||
9 | /* */ | ||||
10 | /* This file is part of the FreeType project, and may only be used, */ | ||||
11 | /* modified, and distributed under the terms of the FreeType project */ | ||||
12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | ||||
13 | /* this file you indicate that you have read the license and */ | ||||
14 | /* understand and accept it fully. */ | ||||
15 | /* */ | ||||
16 | /***************************************************************************/ | ||||
17 | |||||
18 | #include <ft2build.h> | ||||
19 | #include FT_FREETYPE_H<freetype/freetype.h> | ||||
20 | #include FT_TRUETYPE_TAGS_H<freetype/tttags.h> | ||||
21 | #include FT_INTERNAL_OBJECTS_H<freetype/internal/ftobjs.h> | ||||
22 | #include FT_INTERNAL_STREAM_H<freetype/internal/ftstream.h> | ||||
23 | #include FT_SERVICE_SFNT_H<freetype/internal/services/svsfnt.h> | ||||
24 | #include FT_SERVICE_TRUETYPE_GLYF_H<freetype/internal/services/svttglyf.h> | ||||
25 | |||||
26 | |||||
27 | static FT_Bool | ||||
28 | _tt_check_patents_in_range( FT_Stream stream, | ||||
29 | FT_ULong size ) | ||||
30 | { | ||||
31 | FT_Bool result = FALSE0; | ||||
32 | FT_Error error; | ||||
33 | FT_Bytes p, end; | ||||
34 | |||||
35 | |||||
36 | if ( FT_FRAME_ENTER( size )( ( error = ((FT_Stream_EnterFrame( stream, size ))) ) != 0 ) ) | ||||
37 | return 0; | ||||
38 | |||||
39 | p = stream->cursor; | ||||
40 | end = p + size; | ||||
41 | |||||
42 | while ( p < end ) | ||||
43 | { | ||||
44 | switch (p[0]) | ||||
45 | { | ||||
46 | case 0x06: /* SPvTL // */ | ||||
47 | case 0x07: /* SPvTL + */ | ||||
48 | case 0x08: /* SFvTL // */ | ||||
49 | case 0x09: /* SFvTL + */ | ||||
50 | case 0x0A: /* SPvFS */ | ||||
51 | case 0x0B: /* SFvFS */ | ||||
52 | result = TRUE1; | ||||
53 | goto Exit; | ||||
54 | |||||
55 | case 0x40: | ||||
56 | if ( p + 1 >= end ) | ||||
57 | goto Exit; | ||||
58 | |||||
59 | p += p[1] + 2; | ||||
60 | break; | ||||
61 | |||||
62 | case 0x41: | ||||
63 | if ( p + 1 >= end ) | ||||
64 | goto Exit; | ||||
65 | |||||
66 | p += p[1] * 2 + 2; | ||||
67 | break; | ||||
68 | |||||
69 | case 0x71: /* DELTAP2 */ | ||||
70 | case 0x72: /* DELTAP3 */ | ||||
71 | case 0x73: /* DELTAC0 */ | ||||
72 | case 0x74: /* DELTAC1 */ | ||||
73 | case 0x75: /* DELTAC2 */ | ||||
74 | result = TRUE1; | ||||
75 | goto Exit; | ||||
76 | |||||
77 | case 0xB0: | ||||
78 | case 0xB1: | ||||
79 | case 0xB2: | ||||
80 | case 0xB3: | ||||
81 | case 0xB4: | ||||
82 | case 0xB5: | ||||
83 | case 0xB6: | ||||
84 | case 0xB7: | ||||
85 | p += ( p[0] - 0xB0 ) + 2; | ||||
86 | break; | ||||
87 | |||||
88 | case 0xB8: | ||||
89 | case 0xB9: | ||||
90 | case 0xBA: | ||||
91 | case 0xBB: | ||||
92 | case 0xBC: | ||||
93 | case 0xBD: | ||||
94 | case 0xBE: | ||||
95 | case 0xBF: | ||||
96 | p += ( p[0] - 0xB8 ) * 2 + 3; | ||||
97 | break; | ||||
98 | |||||
99 | default: | ||||
100 | p += 1; | ||||
101 | break; | ||||
102 | } | ||||
103 | } | ||||
104 | |||||
105 | Exit: | ||||
106 | FT_UNUSED( error )( (error) = (error) ); | ||||
107 | FT_FRAME_EXIT()(FT_Stream_ExitFrame( stream )); | ||||
108 | return result; | ||||
109 | } | ||||
110 | |||||
111 | |||||
112 | static FT_Bool | ||||
113 | _tt_check_patents_in_table( FT_Face face, | ||||
114 | FT_ULong tag ) | ||||
115 | { | ||||
116 | FT_Stream stream = face->stream; | ||||
117 | FT_Error error = FT_Err_Ok; | ||||
118 | FT_Service_SFNT_Table service; | ||||
119 | FT_Bool result = FALSE0; | ||||
120 | |||||
121 | |||||
122 | FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE )do { FT_Module module = ((FT_Module)( ((FT_Face)(face))->driver )); FT_Pointer _tmp_ = ((void*)0); if ( module->clazz-> get_interface ) _tmp_ = module->clazz->get_interface( module , "sfnt-table" ); service = _tmp_; } while ( 0 ); | ||||
123 | |||||
124 | if ( service ) | ||||
| |||||
125 | { | ||||
126 | FT_UInt i = 0; | ||||
127 | FT_ULong tag_i = 0, offset_i, length_i; | ||||
| |||||
128 | |||||
129 | for ( i = 0; !error && tag_i != tag ; i++ ) | ||||
| |||||
130 | error = service->table_info( face, i, | ||||
131 | &tag_i, &offset_i, &length_i ); | ||||
132 | |||||
133 | if ( error || | ||||
134 | FT_STREAM_SEEK( offset_i )( ( error = (FT_Stream_Seek( stream, offset_i )) ) != 0 ) ) | ||||
| |||||
135 | goto Exit; | ||||
136 | |||||
137 | result = _tt_check_patents_in_range( stream, length_i ); | ||||
138 | } | ||||
139 | |||||
140 | Exit: | ||||
141 | return result; | ||||
142 | } | ||||
143 | |||||
144 | |||||
145 | static FT_Bool | ||||
146 | _tt_face_check_patents( FT_Face face ) | ||||
147 | { | ||||
148 | FT_Stream stream = face->stream; | ||||
149 | FT_UInt gindex; | ||||
150 | FT_Error error; | ||||
151 | FT_Bool result; | ||||
152 | |||||
153 | FT_Service_TTGlyf service; | ||||
154 | |||||
155 | |||||
156 | result = _tt_check_patents_in_table( face, TTAG_fpgm(FT_Tag) ( ( (FT_ULong)'f' << 24 ) | ( (FT_ULong)'p' << 16 ) | ( (FT_ULong)'g' << 8 ) | (FT_ULong)'m' ) ); | ||||
157 | if ( result ) | ||||
158 | goto Exit; | ||||
159 | |||||
160 | result = _tt_check_patents_in_table( face, TTAG_prep(FT_Tag) ( ( (FT_ULong)'p' << 24 ) | ( (FT_ULong)'r' << 16 ) | ( (FT_ULong)'e' << 8 ) | (FT_ULong)'p' ) ); | ||||
161 | if ( result ) | ||||
162 | goto Exit; | ||||
163 | |||||
164 | FT_FACE_FIND_SERVICE( face, service, TT_GLYF )do { FT_Module module = ((FT_Module)( ((FT_Face)(face))->driver )); FT_Pointer _tmp_ = ((void*)0); if ( module->clazz-> get_interface ) _tmp_ = module->clazz->get_interface( module , "tt-glyf" ); service = _tmp_; } while ( 0 ); | ||||
165 | if ( service == NULL((void*)0) ) | ||||
166 | goto Exit; | ||||
167 | |||||
168 | for ( gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++ ) | ||||
169 | { | ||||
170 | FT_ULong offset, num_ins, size; | ||||
171 | FT_Int num_contours; | ||||
172 | |||||
173 | |||||
174 | offset = service->get_location( face, gindex, &size ); | ||||
175 | if ( size == 0 ) | ||||
176 | continue; | ||||
177 | |||||
178 | if ( FT_STREAM_SEEK( offset )( ( error = (FT_Stream_Seek( stream, offset )) ) != 0 ) || | ||||
179 | FT_READ_SHORT( num_contours )( num_contours = (FT_Short)FT_Stream_ReadShort( stream, & error ), error != FT_Err_Ok ) ) | ||||
180 | continue; | ||||
181 | |||||
182 | if ( num_contours >= 0 ) /* simple glyph */ | ||||
183 | { | ||||
184 | if ( FT_STREAM_SKIP( 8 + num_contours * 2 )( ( error = (FT_Stream_Skip( stream, 8 + num_contours * 2 )) ) != 0 ) ) | ||||
185 | continue; | ||||
186 | } | ||||
187 | else /* compound glyph */ | ||||
188 | { | ||||
189 | FT_Bool has_instr = 0; | ||||
190 | |||||
191 | |||||
192 | if ( FT_STREAM_SKIP( 8 )( ( error = (FT_Stream_Skip( stream, 8 )) ) != 0 ) ) | ||||
193 | continue; | ||||
194 | |||||
195 | /* now read each component */ | ||||
196 | for (;;) | ||||
197 | { | ||||
198 | FT_UInt flags, toskip; | ||||
199 | |||||
200 | |||||
201 | if( FT_READ_USHORT( flags )( flags = (FT_UShort)FT_Stream_ReadShort( stream, &error ) , error != FT_Err_Ok ) ) | ||||
202 | break; | ||||
203 | |||||
204 | toskip = 2 + 1 + 1; | ||||
205 | |||||
206 | if ( ( flags & ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */ | ||||
207 | toskip += 2; | ||||
208 | |||||
209 | if ( ( flags & ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */ | ||||
210 | toskip += 2; | ||||
211 | else if ( ( flags & ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */ | ||||
212 | toskip += 4; | ||||
213 | else if ( ( flags & ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */ | ||||
214 | toskip += 8; | ||||
215 | |||||
216 | if ( ( flags & ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */ | ||||
217 | has_instr = 1; | ||||
218 | |||||
219 | if ( FT_STREAM_SKIP( toskip )( ( error = (FT_Stream_Skip( stream, toskip )) ) != 0 ) ) | ||||
220 | goto NextGlyph; | ||||
221 | |||||
222 | if ( ( flags & ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */ | ||||
223 | break; | ||||
224 | } | ||||
225 | |||||
226 | if ( !has_instr ) | ||||
227 | goto NextGlyph; | ||||
228 | } | ||||
229 | |||||
230 | if ( FT_READ_USHORT( num_ins )( num_ins = (FT_UShort)FT_Stream_ReadShort( stream, &error ), error != FT_Err_Ok ) ) | ||||
231 | continue; | ||||
232 | |||||
233 | result = _tt_check_patents_in_range( stream, num_ins ); | ||||
234 | if ( result ) | ||||
235 | goto Exit; | ||||
236 | |||||
237 | NextGlyph: | ||||
238 | ; | ||||
239 | } | ||||
240 | |||||
241 | Exit: | ||||
242 | return result; | ||||
243 | } | ||||
244 | |||||
245 | |||||
246 | /* documentation is in freetype.h */ | ||||
247 | |||||
248 | FT_EXPORT_DEF( FT_Bool )extern FT_Bool | ||||
249 | FT_Face_CheckTrueTypePatents( FT_Face face ) | ||||
250 | { | ||||
251 | FT_Bool result = FALSE0; | ||||
252 | |||||
253 | |||||
254 | if ( face && FT_IS_SFNT( face )( face->face_flags & ( 1L << 3 ) ) ) | ||||
255 | result = _tt_face_check_patents( face ); | ||||
256 | |||||
257 | return result; | ||||
258 | } | ||||
259 | |||||
260 | |||||
261 | /* documentation is in freetype.h */ | ||||
262 | |||||
263 | FT_EXPORT_DEF( FT_Bool )extern FT_Bool | ||||
264 | FT_Face_SetUnpatentedHinting( FT_Face face, | ||||
265 | FT_Bool value ) | ||||
266 | { | ||||
267 | FT_Bool result = FALSE0; | ||||
268 | |||||
269 | |||||
270 | #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \ | ||||
271 | !defined( TT_CONFIG_OPTION_BYTECODE_INTEPRETER ) | ||||
272 | if ( face && FT_IS_SFNT( face )( face->face_flags & ( 1L << 3 ) ) ) | ||||
273 | { | ||||
274 | result = !face->internal->ignore_unpatented_hinter; | ||||
275 | face->internal->ignore_unpatented_hinter = !value; | ||||
276 | } | ||||
277 | #else | ||||
278 | FT_UNUSED( face )( (face) = (face) ); | ||||
279 | FT_UNUSED( value )( (value) = (value) ); | ||||
280 | #endif | ||||
281 | |||||
282 | return result; | ||||
283 | } | ||||
284 | |||||
285 | /* END */ |