History

properly handle font loading errors

Sigrid Solveig Haflínudóttir committed 5 years agomaster

Commit 07102961 parent e771f322 files · +10 −2Browse files

Unified · Split

2 files
  1. pt.c +8 −1
  2. test.c +2 −1
pt.c+8−1
@@ -102,8 +102,10 @@ pt_font(uchar *data, float height) · 101 unmodified lines
102102 Sfont *f;
103103
104104 f = mallocz(sizeof(*f), 1);
105− if(stbtt_InitFont(&f->fi, data, stbtt_GetFontOffsetForIndex(data, 0)) == 0)
105+ if(stbtt_InitFont(&f->fi, data, stbtt_GetFontOffsetForIndex(data, 0)) == 0){
106+ werrstr("stbtt_InitFont: %r");
106107 goto err;
108+ }
107109
108110 f->scale = stbtt_ScaleForPixelHeight(&f->fi, height);
109111 f->height = height;
@@ -119,6 +121,10 @@ pt_font(uchar *data, float height) · 9 unmodified lines
119121 f->bb.max.x = (f->bb.max.x + 3) & ~3;
120122 f->bb.max.y = (f->bb.max.y + 3) & ~3;
121123
124+ if(badrect(f->bb)){
125+ werrstr("invalid glyph bbox: %R", f->bb);
126+ goto err;
127+ }
122128 if((f->g = allocmemimage(f->bb, GREY8)) == nil)
123129 goto err;
124130 if((f->b = allocmemimage(f->bb, GREY8)) == nil)
@@ -127,6 +133,7 @@ pt_font(uchar *data, float height) · 2 unmodified lines
127133
128134 return f;
129135 err:
136+ werrstr("pt_font: %r");
130137 pt_freefont(f);
131138 return nil;
132139 }
test.c+2−1
@@ -193,7 +193,8 @@ threadmain(int argc, char **argv) · 192 unmodified lines
193193
194194 changed:
195195 pt_freefont(fo);
196− fo = pt_font(data, height);
196+ if((fo = pt_font(data, height)) == nil)
197+ sysfatal("%r");
197198 rect = pt_textrect(fo, s);
198199 freeimage(image);
199200 image = pt_textdraw(fo, s, rect, &opts);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t