From 54736b9c3c05a00e9302e6f75694aa207e35140b Mon Sep 17 00:00:00 2001 From: piepie62 Date: Wed, 27 Mar 2019 17:38:57 -0700 Subject: [PATCH] Requested changes --- libctru/include/3ds/font.h | 3 +-- libctru/source/font.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libctru/include/3ds/font.h b/libctru/include/3ds/font.h index c10d6f1..c546782 100644 --- a/libctru/include/3ds/font.h +++ b/libctru/include/3ds/font.h @@ -160,8 +160,7 @@ Result fontEnsureMapped(void); /** * @brief Fixes the pointers internal to a just-loaded font * @param font Font to fix - * @remark Should never be run on the system font, and only once - * on any other font. + * @remark Should never be run on the system font, and only once on any other font. */ void fontFixPointers(CFNT_s* font); diff --git a/libctru/source/font.c b/libctru/source/font.c index 2960ece..9427242 100644 --- a/libctru/source/font.c +++ b/libctru/source/font.c @@ -34,13 +34,11 @@ void fontFixPointers(CFNT_s* font) font->finf.tglp->sheetData = (u8*)((u32)(font->finf.tglp->sheetData) + (u32) font); font->finf.cmap = (CMAP_s*)((u32)(font->finf.cmap) + (u32) font); - CMAP_s* cmap = font->finf.cmap; - for (; cmap->next; cmap = cmap->next) + for (CMAP_s* cmap = font->finf.cmap; cmap->next; cmap = cmap->next) cmap->next = (CMAP_s*)((u32)(cmap->next) + (u32) font); font->finf.cwdh = (CWDH_s*)((u32)(font->finf.cwdh) + (u32) font); - CWDH_s* cwdh; - for (cwdh = font->finf.cwdh; cwdh->next; cwdh = cwdh->next) + for (CWDH_s* cwdh = font->finf.cwdh; cwdh->next; cwdh = cwdh->next) cwdh->next = (CWDH_s*)((u32)(cwdh->next) + (u32) font); } @@ -48,6 +46,8 @@ int fontGlyphIndexFromCodePoint(CFNT_s* font, u32 codePoint) { if (!font) font = g_sharedFont; + if (!font) + return -1; int ret = font->finf.alterCharIndex; if (codePoint < 0x10000) { @@ -87,6 +87,8 @@ charWidthInfo_s* fontGetCharWidthInfo(CFNT_s* font, int glyphIndex) { if (!font) font = g_sharedFont; + if (!font) + return NULL; charWidthInfo_s* info = NULL; CWDH_s* cwdh; for (cwdh = font->finf.cwdh; cwdh && !info; cwdh = cwdh->next) @@ -104,6 +106,8 @@ void fontCalcGlyphPos(fontGlyphPos_s* out, CFNT_s* font, int glyphIndex, u32 fla { if (!font) font = g_sharedFont; + if (!font) + return; FINF_s* finf = &font->finf; TGLP_s* tglp = finf->tglp; charWidthInfo_s* cwi = fontGetCharWidthInfo(font, glyphIndex);