summarylogtreecommitdiffstats
path: root/0003-check-for-freetype-NULL-atoms.patch
blob: 7c28748beeed46a1db58ddbe11c310a0bd52458b (plain)
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
From 6fc84fb2c0d4ac0b3b66330057bb90418cc1eb28 Mon Sep 17 00:00:00 2001
From: Ryan Farley <ryan.farley@gmx.com>
Date: Fri, 30 Aug 2019 09:43:50 -0500
Subject: [PATCH app/fonttosfnt] check for freetype NULL atoms

Freetype uses NULL to represent an empty string when retrieving a BDF
property -- check for this in addition to an actual error
---
 util.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/util.c b/util.c
index 5a23eeb..bcbfa2f 100644
--- a/util.c
+++ b/util.c
@@ -127,7 +127,7 @@ vsprintf_alloc(const char *f, va_list args)
 }
 #endif
 
-/* Build a UTF-16 string from a Latin-1 string.  
+/* Build a UTF-16 string from a Latin-1 string.
    Result is not NUL-terminated. */
 char *
 makeUTF16(const char *string)
@@ -241,7 +241,7 @@ faceFoundry(FT_Face face)
     BDF_PropertyRec prop;
 
     rc = FT_Get_BDF_Property(face, "FOUNDRY", &prop);
-    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
+    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom) {
         if(strcasecmp(prop.u.atom, "adobe") == 0)
             return makeName("ADBE");
         else if(strcasecmp(prop.u.atom, "agfa") == 0)
@@ -286,7 +286,7 @@ faceFoundry(FT_Face face)
     /* For now */
     return makeName("UNKN");
 }
-    
+
 
 int
 faceWeight(FT_Face face)
@@ -294,7 +294,7 @@ faceWeight(FT_Face face)
     int rc;
     BDF_PropertyRec prop;
     rc = FT_Get_BDF_Property(face, "WEIGHT_NAME", &prop);
-    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
+    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom) {
         if(strcasecmp(prop.u.atom, "thin") == 0)
             return 100;
         else if(strcasecmp(prop.u.atom, "extralight") == 0)
@@ -323,7 +323,7 @@ faceWidth(FT_Face face)
     int rc;
     BDF_PropertyRec prop;
     rc = FT_Get_BDF_Property(face, "SETWIDTH_NAME", &prop);
-    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
+    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom) {
         if(strcasecmp(prop.u.atom, "ultracondensed") == 0)
             return 1;
         else if(strcasecmp(prop.u.atom, "extracondensed") == 0)
@@ -360,7 +360,7 @@ faceItalicAngle(FT_Face face)
     }
 
     rc = FT_Get_BDF_Property(face, "SLANT", &prop);
-    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
+    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom) {
         if(strcasecmp(prop.u.atom, "i") == 0 ||
            strcasecmp(prop.u.atom, "s") == 0)
             return -30 * TWO_SIXTEENTH;
@@ -380,7 +380,7 @@ faceFlags(FT_Face face)
     if(faceWeight(face) >= 650)
         flags |= FACE_BOLD;
     rc = FT_Get_BDF_Property(face, "SLANT", &prop);
-    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM) {
+    if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM && prop.u.atom) {
         if(strcasecmp(prop.u.atom, "i") == 0 ||
            strcasecmp(prop.u.atom, "s") == 0)
             flags |= FACE_ITALIC;
@@ -400,10 +400,12 @@ faceEncoding(FT_Face face)
     rc = FT_Get_BDF_Property(face, "CHARSET_ENCODING", &p2);
     if(rc != 0 || p2.type != BDF_PROPERTY_TYPE_ATOM)
         return NULL;
+    if(!(p1.u.atom && p2.u.atom))
+        return NULL;
 
     return sprintf_alloc("%s-%s", p1.u.atom, p2.u.atom);
 }
-    
+
 int
 degreesToFraction(int deg, int *num, int *den)
 {
-- 
2.23.0