Commit 2fbf7e439f06416d195435baa89c403f2044c2dd

Werner Lemberg 2000-06-02T00:01:14

Added a lot of error checking code to the exported functions in the `base' subdir (not complete yet).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
diff --git a/src/base/ftextend.c b/src/base/ftextend.c
index 14e9087..550bf30 100644
--- a/src/base/ftextend.c
+++ b/src/base/ftextend.c
@@ -122,6 +122,12 @@
     FT_Extension_Registry*  registry;
 
 
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
+
+    if ( !class )
+      return FT_Err_Invalid_Argument;
+
     registry = (FT_Extension_Registry*)driver->extensions;
     if ( registry )
     {
@@ -172,6 +178,9 @@
     FT_Extension_Registry*  registry;
 
 
+    if ( !face || !extension_id || !extension_interface )
+      return 0;
+
     registry = (FT_Extension_Registry*)face->driver->extensions;
     if ( registry && face->extensions )
     {
@@ -190,6 +199,7 @@
     /* could not find the extension id */
 
     *extension_interface = 0;
+
     return 0;
   }
 
diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c
index c21c84a..3f55748 100644
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -86,7 +86,7 @@
   /*                                                                       */
   /* <Note>                                                                */
   /*    If the font contains glyph outlines, these will be automatically   */
-  /*    converted to a bitmap according to the value of `grays'            */
+  /*    converted to a bitmap according to the value of `grays'.           */
   /*                                                                       */
   /*    If `grays' is set to 0, the result is a 1-bit monochrome bitmap    */
   /*    otherwise, it is an 8-bit gray-level bitmap.                       */
@@ -121,6 +121,12 @@
     FT_Pos           origin_y = 0;
 
 
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
+
+    if ( !abitglyph )
+      return FT_Err_Invalid_Argument;
+
     *abitglyph = 0;
 
     if ( origin )
@@ -304,6 +310,11 @@
     FT_OutlineGlyph  glyph;
 
 
+    /* test for valid face delayed to FT_Load_Glyph() */
+
+    if ( !vecglyph )
+      return FT_Err_Invalid_Argument;
+
     *vecglyph = 0;
 
     /* check that NO_OUTLINE and NO_RECURSE are not set */
@@ -394,6 +405,9 @@
                                             FT_Matrix*  matrix,
                                             FT_Vector*  delta )
   {
+    if ( !face )
+      return;
+
     face->transform_flags = 0;
 
     if ( !matrix )
@@ -496,6 +510,9 @@
   FT_EXPORT_FUNC( void )  FT_Glyph_Get_Box( FT_Glyph  glyph,
                                             FT_BBox*  box )
   {
+    if ( !box )
+      return;
+
     box->xMin = box->xMax = 0;
     box->yMin = box->yMax = 0;
 
@@ -529,7 +546,7 @@
 
       default:
         ;
-    }
+      }
   }
 
 
diff --git a/src/base/ftgrays.c b/src/base/ftgrays.c
index b92a62f..0294fbf 100644
--- a/src/base/ftgrays.c
+++ b/src/base/ftgrays.c
@@ -1632,7 +1632,7 @@
     return error;
 
   Invalid_Outline:
-    return -1;
+    return ErrRaster_Invalid_Outline;
   }
 
 #endif /* _STANDALONE_ */
@@ -1797,11 +1797,11 @@
       return 0;
 
     if ( !outline || !outline->contours || !outline->points )
-      return -1;
+      return ErrRaster_Invalid_Outline;
 
     if ( outline->n_points !=
            outline->contours[outline->n_contours - 1] + 1 )
-      return -1;
+      return ErrRaster_Invalid_Outline;
 
     if ( !target_map || !target_map->buffer )
       return -1;
diff --git a/src/base/ftinit.c b/src/base/ftinit.c
index 65a363a..c24a9c7 100644
--- a/src/base/ftinit.c
+++ b/src/base/ftinit.c
@@ -74,10 +74,12 @@ const FT_DriverInterface*  ft_default_drivers[] =
   /*                                                                       */
   FT_EXPORT_FUNC( void )  FT_Default_Drivers( FT_Library  library )
   {
-    FT_Error                   error;
-    const FT_DriverInterface* *cur;
+    FT_Error                    error;
+    const FT_DriverInterface**  cur;
 
 
+    /* test for valid library delayed to FT_Add_Driver() */
+
     cur = ft_default_drivers;
     while ( *cur )
     {
diff --git a/src/base/ftmm.c b/src/base/ftmm.c
index 42b13d4..66fa35d 100644
--- a/src/base/ftmm.c
+++ b/src/base/ftmm.c
@@ -24,10 +24,13 @@
   {
     FT_Error  error;
 
+
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
     
     error = FT_Err_Invalid_Argument;
 
-    if ( face && FT_HAS_MULTIPLE_MASTERS( face ) )
+    if ( FT_HAS_MULTIPLE_MASTERS( face ) )
     {
       FT_Driver       driver = face->driver;
       FT_Get_MM_Func  func;
@@ -51,9 +54,12 @@
     FT_Error  error;
 
     
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
+
     error = FT_Err_Invalid_Argument;
 
-    if ( face && FT_HAS_MULTIPLE_MASTERS( face ) )
+    if ( FT_HAS_MULTIPLE_MASTERS( face ) )
     {
       FT_Driver              driver = face->driver;
       FT_Set_MM_Design_Func  func;
@@ -77,9 +83,12 @@
     FT_Error  error;
 
     
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
+
     error = FT_Err_Invalid_Argument;
 
-    if ( face && FT_HAS_MULTIPLE_MASTERS( face ) )
+    if ( FT_HAS_MULTIPLE_MASTERS( face ) )
     {
       FT_Driver             driver = face->driver;
       FT_Set_MM_Blend_Func  func;
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index cca71b8..e3f2ef3 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -217,6 +217,8 @@
   /* <Description>                                                         */
   /*    Creates a new input stream object from an FT_Open_Args structure.  */
   /*                                                                       */
+  /* <Note>                                                                */
+  /*    The function expects a valid `astream' parameter.                  */
   static
   FT_Error  ft_new_input_stream( FT_Library     library,
                                  FT_Open_Args*  args,
@@ -227,6 +229,12 @@
     FT_Stream  stream;
 
 
+    if ( !library )
+      return FT_Err_Invalid_Library_Handle;
+
+    if ( !args )
+      return FT_Err_Invalid_Argument;
+
     *astream = 0;
     memory   = library->memory;
     if ( ALLOC( stream, sizeof ( *stream ) ) )
@@ -279,7 +287,7 @@
   /*                                                                       */
   FT_EXPORT_FUNC( void )  FT_Done_Stream( FT_Stream  stream )
   {
-    if ( stream->close )
+    if ( stream && stream->close )
       stream->close( stream );
   }
 
@@ -425,6 +433,9 @@
     FT_Int  n;
 
 
+    if ( !library )
+      return 0;
+
     for ( n = 0; n < FT_MAX_GLYPH_FORMATS; n++ )
     {
       FT_Raster_Funcs*  funcs = &library->raster_funcs[n];
@@ -471,13 +482,21 @@
   FT_EXPORT_FUNC( FT_Error )  FT_Set_Raster( FT_Library        library,
                                              FT_Raster_Funcs*  raster_funcs )
   {
-    FT_Glyph_Format  glyph_format = raster_funcs->glyph_format;
+    FT_Glyph_Format  glyph_format;
     FT_Raster_Funcs* funcs;
     FT_Raster        raster;
     FT_Error         error;
     FT_Int           n, index;
 
 
+    if ( !library )
+      return FT_Err_Invalid_Library_Handle;
+
+    if ( !raster_funcs )
+      return FT_Err_Invalid_Argument;
+
+    glyph_format = raster_funcs->glyph_format;
+
     if ( glyph_format == ft_glyph_format_none )
       return FT_Err_Invalid_Argument;
 
@@ -551,13 +570,21 @@
                                FT_Library        library,
                                FT_Raster_Funcs*  raster_funcs )
   {
-    FT_Glyph_Format  glyph_format = raster_funcs->glyph_format;
+    FT_Glyph_Format  glyph_format;
     FT_Error         error;
     FT_Int           n;
 
 
+    if ( !library )
+      return FT_Err_Invalid_Library_Handle;
+
     error = FT_Err_Invalid_Argument;
 
+    if ( !raster_funcs )
+      goto Exit;
+
+    glyph_format = raster_funcs->glyph_format;
+
     if ( glyph_format == ft_glyph_format_none )
       goto Exit;
 
@@ -611,8 +638,11 @@
     FT_Raster        raster;
 
 
+    if ( !library )
+      return FT_Err_Invalid_Library_Handle;
+
     raster = FT_Get_Raster( library, format, &funcs );
-    if ( raster && funcs.raster_set_mode )
+    if ( raster && args && funcs.raster_set_mode )
       return funcs.raster_set_mode( raster, mode, args );
     else
       return FT_Err_Invalid_Argument;
@@ -645,7 +675,8 @@
                                              FT_UInt            hook_index,
                                              FT_DebugHook_Func  debug_hook )
   {
-    if ( hook_index <
+    if ( library && debug_hook &&
+         hook_index <
            ( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) )
       library->debug_hooks[hook_index] = debug_hook;
   }
@@ -673,9 +704,12 @@
   FT_EXPORT_FUNC( FT_Error )  FT_New_Library( FT_Memory    memory,
                                               FT_Library*  alibrary )
   {
-    FT_Library library = 0;
-    FT_Error   error;
+    FT_Library  library = 0;
+    FT_Error    error;
+
 
+    if ( !memory )
+      return FT_Err_Invalid_Argument;
 
     /* first of all, allocate the library object */
     if ( ALLOC( library, sizeof ( *library ) ) )
@@ -804,9 +838,12 @@
     FT_Memory  memory;
 
 
-    if ( !library || !driver_interface )
+    if ( !library )
       return FT_Err_Invalid_Library_Handle;
 
+    if ( !driver_interface )
+      return FT_Err_Invalid_Argument;
+
     memory = library->memory;
     error  = FT_Err_Ok;
 
@@ -1041,6 +1078,11 @@
     FT_Open_Args  args;
 
 
+    /* test for valid `library' and `aface' delayed to FT_Open_Face() */
+
+    if ( !pathname )
+      return FT_Err_Invalid_Argument;
+
     args.flags    = ft_open_pathname;
     args.pathname = (char*)pathname;
 
@@ -1097,6 +1139,11 @@
     FT_Open_Args  args;
 
 
+    /* test for valid `library' and `face' delayed to FT_Open_Face() */
+
+    if ( !file_base )
+      return FT_Err_Invalid_Argument;
+
     args.flags       = ft_open_memory;
     args.memory_base = file_base;
     args.memory_size = file_size;
@@ -1158,10 +1205,13 @@
     FT_ListNode  node = 0;
 
 
-    *aface = 0;
+    /* test for valid `library' and `args' delayed to */
+    /* ft_new_input_stream()                          */
 
-    if ( !library )
-      return FT_Err_Invalid_Handle;
+    if ( !aface )
+      return FT_Err_Invalid_Argument;
+
+    *aface = 0;
 
     /* create input stream */
     error = ft_new_input_stream( library, args, &stream );
@@ -1328,6 +1378,11 @@
     FT_Open_Args  open;
 
 
+    /* test for valid `face' delayed to FT_Attach_Stream() */
+
+    if ( !filepathname )
+      return FT_Err_Invalid_Argument;
+
     open.flags    = ft_open_pathname;
     open.pathname = (char*)filepathname;
 
@@ -1371,11 +1426,16 @@
     FTDriver_getInterface  get_interface;
 
 
-    if ( !face || !face->driver )
-      return FT_Err_Invalid_Handle;
+    /* test for valid `parameters' delayed to ft_new_input_stream() */
+
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
 
     driver = face->driver;
-    error  = ft_new_input_stream( driver->library, parameters, &stream );
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
+
+    error = ft_new_input_stream( driver->library, parameters, &stream );
     if ( error )
       goto Exit;
 
@@ -1427,10 +1487,13 @@
     FT_ListNode          node;
 
 
-    if ( !face || !face->driver )
+    if ( !face )
       return FT_Err_Invalid_Face_Handle;
 
-    driver    = face->driver;
+    driver = face->driver;
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
+
     interface = &driver->interface;
     memory    = driver->memory;
 
@@ -1482,11 +1545,18 @@
     FT_ListNode          node = 0;
 
 
-    if ( !face || !face->driver )
+    if ( !face )
       return FT_Err_Invalid_Face_Handle;
 
-    *asize    = 0;
-    driver    = face->driver;
+    if ( !asize )
+      return FT_Err_Invalid_Argument;
+
+    *asize = 0;
+
+    driver = face->driver;
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
+
     interface = &driver->interface;
     memory    = face->memory;
 
@@ -1544,17 +1614,20 @@
     FT_ListNode  node;
 
 
-    if ( !size || !size->face )
+    if ( !size )
       return FT_Err_Invalid_Size_Handle;
 
-    driver = size->face->driver;
+    face = size->face;
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
+
+    driver = face->driver;
     if ( !driver )
       return FT_Err_Invalid_Driver_Handle;
 
     memory = driver->memory;
 
     error = FT_Err_Ok;
-    face  = size->face;
     node  = FT_List_Find( &face->sizes_list, size );
     if ( node )
     {
@@ -1621,13 +1694,22 @@
     FT_Driver            driver;
     FT_Memory            memory;
     FT_DriverInterface*  interface;
-    FT_Size_Metrics*     metrics = &face->size->metrics;
+    FT_Size_Metrics*     metrics;
     FT_Long              dim_x, dim_y;
 
 
-    if ( !face || !face->size || !face->driver )
+    if ( !face )
       return FT_Err_Invalid_Face_Handle;
 
+    if ( !face->size )
+      return FT_Err_Invalid_Size_Handle;
+
+    driver = face->driver;
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
+
+    metrics = &face->size->metrics;
+
     if ( !char_width )
       char_width = char_height;
     else if ( !char_height )
@@ -1705,10 +1787,16 @@
     FT_Size_Metrics*     metrics = &face->size->metrics;
 
 
-    if ( !face || !face->size || !face->driver )
+    if ( !face )
       return FT_Err_Invalid_Face_Handle;
 
-    driver    = face->driver;
+    if ( !face->size )
+      return FT_Err_Invalid_Size_Handle;
+
+    driver = face->driver;
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
+
     interface = &driver->interface;
     memory    = driver->memory;
 
@@ -1770,12 +1858,18 @@
     FT_GlyphSlot         slot;
 
 
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
+
+    if ( !aslot )
+      return FT_Err_Invalid_Argument;
+
     *aslot = 0;
 
-    if ( !face || !face->driver )
-      return FT_Err_Invalid_Face_Handle;
+    driver = face->driver;
+    if ( !driver )
+      return FT_Err_Invalid_Driver_Handle;
 
-    driver    = face->driver;
     interface = &driver->interface;
     memory    = driver->memory;
 
@@ -1880,9 +1974,15 @@
     FT_Driver  driver;
 
 
-    if ( !face || !face->size || !face->glyph )
+    if ( !face )
       return FT_Err_Invalid_Face_Handle;
 
+    if ( !face->size )
+      return FT_Err_Invalid_Size_Handle;
+
+    if ( !face->glyph )
+      return FT_Err_Invalid_Slot_Handle;
+
     if ( glyph_index >= face->num_glyphs )
       return FT_Err_Invalid_Argument;
       
@@ -1935,9 +2035,18 @@
     FT_UInt    glyph_index;
 
 
-    if ( !face || !face->size || !face->glyph || !face->charmap )
+    if ( !face )
       return FT_Err_Invalid_Face_Handle;
 
+    if ( !face->size )
+      return FT_Err_Invalid_Size_Handle;
+
+    if ( !face->glyph )
+      return FT_Err_Invalid_Slot_Handle;
+
+    if ( !face->charmap )
+      return FT_Err_Invalid_CharMap_Handle;
+
     driver      = face->driver;
     glyph_index = FT_Get_Char_Index( face, char_code );
 
@@ -1986,16 +2095,16 @@
                                               FT_UInt     right_glyph,
                                               FT_Vector*  kerning )
   {
-    FT_Error   error;
+    FT_Error   error = FT_Err_Ok;
     FT_Driver  driver;
     FT_Memory  memory;
 
 
     if ( !face )
-    {
-      error = FT_Err_Invalid_Face_Handle;
-      goto Exit;
-    }
+      return FT_Err_Invalid_Face_Handle;
+
+    if ( !kerning )
+      return FT_Err_Invalid_Argument;
 
     driver = face->driver;
     memory = driver->memory;
@@ -2011,10 +2120,8 @@
     {
       kerning->x = 0;
       kerning->y = 0;
-      error      = FT_Err_Ok;
     }
 
-  Exit:
     return error;
   }
 
@@ -2043,9 +2150,18 @@
   FT_EXPORT_FUNC( FT_Error )  FT_Select_Charmap( FT_Face      face,
                                                  FT_Encoding  encoding )
   {
-    FT_CharMap*  cur   = face->charmaps;
-    FT_CharMap*  limit = cur + face->num_charmaps;
+    FT_CharMap*  cur;
+    FT_CharMap*  limit;
+
+
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
 
+    cur = face->charmaps;
+    if ( !cur )
+      return FT_Err_Invalid_CharMap_Handle;
+
+    limit = cur + face->num_charmaps;
 
     for ( ; cur < limit; cur++ )
     {
@@ -2083,9 +2199,18 @@
   FT_EXPORT_FUNC( FT_Error )  FT_Set_Charmap( FT_Face     face,
                                               FT_CharMap  charmap )
   {
-    FT_CharMap*  cur   = face->charmaps;
-    FT_CharMap*  limit = cur + face->num_charmaps;
+    FT_CharMap*  cur;
+    FT_CharMap*  limit;
+
 
+    if ( !face )
+      return FT_Err_Invalid_Face_Handle;
+
+    cur = face->charmaps;
+    if ( !cur )
+      return FT_Err_Invalid_CharMap_Handle;
+
+    limit = cur + face->num_charmaps;
 
     for ( ; cur < limit; cur++ )
     {
@@ -2115,8 +2240,8 @@
   /* <Return>                                                              */
   /*    The glyph index.  0 means `undefined character code'.              */
   /*                                                                       */
-  FT_EXPORT_FUNC( FT_UInt )  FT_Get_Char_Index( FT_Face  face,
-                                                FT_ULong charcode )
+  FT_EXPORT_FUNC( FT_UInt )  FT_Get_Char_Index( FT_Face   face,
+                                                FT_ULong  charcode )
   {
     FT_UInt    result;
     FT_Driver  driver;
@@ -2197,6 +2322,8 @@
   /*                                                                       */
   FT_EXPORT_FUNC( FT_Error )  FT_Done_FreeType( FT_Library  library )
   {
+    /* test for valid `library' delayed to FT_Done_Library() */
+
     /* Discard the library object */
     FT_Done_Library( library );
 
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index 22c30c4..600efa4 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -77,10 +77,15 @@
     FT_UInt  first;     /* index of first point in contour */
     char     tag;       /* current point's state           */
 
-    FT_Int   shift = interface->shift;
-    FT_Pos   delta = interface->delta;
+    FT_Int   shift;
+    FT_Pos   delta;
 
 
+    if ( !outline || !interface )
+      return FT_Err_Invalid_Argument;
+
+    shift = interface->shift;
+    delta = interface->delta;
     first = 0;
 
     for ( n = 0; n < outline->n_contours; n++ )
@@ -718,6 +723,12 @@
     FT_Raster_Params  params;
 
 
+    if ( !library )
+      return FT_Err_Invalid_Library_Handle;
+
+    if ( !outline || !bitmap )
+      return FT_Err_Invalid_Argument;
+
     error  = FT_Err_Invalid_Glyph_Format;
     raster = FT_Get_Raster( library, ft_glyph_format_outline, &funcs );
     if ( !raster )
@@ -770,15 +781,21 @@
   /*    converter is called, which means that the value you give to it is  */
   /*    actually ignored.                                                  */
   /*                                                                       */
-  FT_EXPORT_FUNC( FT_Error )  FT_Outline_Render( FT_Library        library,
-                                                 FT_Outline*       outline,
-                                                 FT_Raster_Params* params )
+  FT_EXPORT_FUNC( FT_Error )  FT_Outline_Render( FT_Library         library,
+                                                 FT_Outline*        outline,
+                                                 FT_Raster_Params*  params )
   {
     FT_Error         error;
     FT_Raster        raster;
     FT_Raster_Funcs  funcs;
 
 
+    if ( !library )
+      return FT_Err_Invalid_Library_Handle;
+
+    if ( !outline || !params )
+      return FT_Err_Invalid_Argument;
+
     error  = FT_Err_Invalid_Glyph_Format;
     raster = FT_Get_Raster( library, ft_glyph_format_outline, &funcs );
     if ( !raster )
@@ -925,12 +942,18 @@
   /* <MT-Note>                                                             */
   /*    Yes.                                                               */
   /*                                                                       */
+  /* <Note>                                                                */
+  /*    The result is undefined if either `vector' or `matrix' is invalid. */
+  /*                                                                       */
   FT_EXPORT_FUNC( void )  FT_Vector_Transform( FT_Vector*  vector,
                                                FT_Matrix*  matrix )
   {
     FT_Pos xz, yz;
 
 
+    if ( !vector || !matrix )
+      return;
+
     xz = FT_MulFix( vector->x, matrix->xx ) +
          FT_MulFix( vector->y, matrix->xy );
 
diff --git a/src/base/ftraster.c b/src/base/ftraster.c
index e787456..8f6f981 100644
--- a/src/base/ftraster.c
+++ b/src/base/ftraster.c
@@ -2059,12 +2059,12 @@
   }
 
 
-  static void
-  Vertical_Sweep_Drop( RAS_ARGS Short       y,
-                                FT_F26Dot6  x1,
-                                FT_F26Dot6  x2,
-                                PProfile    left,
-                                PProfile    right )
+  static
+  void Vertical_Sweep_Drop( RAS_ARGS Short       y,
+                                     FT_F26Dot6  x1,
+                                     FT_F26Dot6  x2,
+                                     PProfile    left,
+                                     PProfile    right )
   {
     Long   e1, e2;
     Short  c1, f1;
diff --git a/src/cff/t2load.c b/src/cff/t2load.c
index a856542..f98173f 100644
--- a/src/cff/t2load.c
+++ b/src/cff/t2load.c
@@ -112,14 +112,17 @@
   static
   void  t2_done_cff_index( CFF_Index*  index )
   {
-    FT_Stream  stream = index->stream;
-    FT_Memory  memory = stream->memory;
+    if ( index->stream )
+    {
+      FT_Stream  stream = index->stream;
+      FT_Memory  memory = stream->memory;
     
-    if (index->bytes)
-      RELEASE_Frame( index->bytes );
+      if (index->bytes)
+        RELEASE_Frame( index->bytes );
 
-    FREE( index->offsets );
-    MEM_Set( index, 0, sizeof(*index) );
+      FREE( index->offsets );
+      MEM_Set( index, 0, sizeof(*index) );
+    }
   }