From b3ba618c2a62854288f976fc4eb5042070d5b63e Mon Sep 17 00:00:00 2001
From: inmarket <inmarket@ugfx.org>
Date: Sat, 1 Oct 2016 18:54:18 +1000
Subject: Add protection for a font not being supplied.

---
 src/gdisp/gdisp.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

(limited to 'src/gdisp')

diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c
index 3925bbee..691cab85 100644
--- a/src/gdisp/gdisp.c
+++ b/src/gdisp/gdisp.c
@@ -3202,6 +3202,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 	#endif
 
 	void gdispGDrawChar(GDisplay *g, coord_t x, coord_t y, uint16_t c, font_t font, color_t color) {
+		if (!font)
+			return;
 		MUTEX_ENTER(g);
 		g->t.font = font;
 		g->t.clipx0 = x;
@@ -3215,6 +3217,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 	}
 
 	void gdispGFillChar(GDisplay *g, coord_t x, coord_t y, uint16_t c, font_t font, color_t color, color_t bgcolor) {
+		if (!font)
+			return;
 		MUTEX_ENTER(g);
 		g->p.cx = mf_character_width(font, c) + font->baseline_x;
 		g->p.cy = font->height;
@@ -3235,6 +3239,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 	}
 
 	void gdispGDrawString(GDisplay *g, coord_t x, coord_t y, const char *str, font_t font, color_t color) {
+		if (!font)
+			return;
 		MUTEX_ENTER(g);
 		g->t.font = font;
 		g->t.clipx0 = x;
@@ -3249,6 +3255,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 	}
 
 	void gdispGFillString(GDisplay *g, coord_t x, coord_t y, const char *str, font_t font, color_t color, color_t bgcolor) {
+		if (!font)
+			return;
 		MUTEX_ENTER(g);
 		g->p.cx = mf_get_string_width(font, str, 0, 0) + font->baseline_x;
 		g->p.cy = font->height;
@@ -3275,6 +3283,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 			uint16_t nbrLines;
 		#endif
 
+		if (!font)
+			return;
 		MUTEX_ENTER(g);
 
 		g->t.font = font;
@@ -3326,6 +3336,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 			uint16_t nbrLines;
 		#endif
 
+		if (!font)
+			return;
 		MUTEX_ENTER(g);
 
 		g->p.cx = cx;
@@ -3382,6 +3394,8 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 	}
 
 	coord_t gdispGetFontMetric(font_t font, fontmetric_t metric) {
+		if (!font)
+			return 0;
 		/* No mutex required as we only read static data */
 		switch(metric) {
 		case fontHeight:			return font->height;
@@ -3397,12 +3411,14 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
 	}
 
 	coord_t gdispGetCharWidth(char c, font_t font) {
+		if (!font)
+			return 0;
 		/* No mutex required as we only read static data */
 		return mf_character_width(font, c);
 	}
 
 	coord_t gdispGetStringWidthCount(const char* str, font_t font, uint16_t count) {
-		if (!str)
+		if (!str || !font)
 			return 0;
 
 		// No mutex required as we only read static data
-- 
cgit v1.2.3