mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
Added security check in case init fails #1135
This commit is contained in:
11
src/text.c
11
src/text.c
@ -504,10 +504,11 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
|||||||
|
|
||||||
if (fileData != NULL)
|
if (fileData != NULL)
|
||||||
{
|
{
|
||||||
// Init font for data reading
|
int genFontChars = false;
|
||||||
stbtt_fontinfo fontInfo;
|
stbtt_fontinfo fontInfo = { 0 };
|
||||||
if (!stbtt_InitFont(&fontInfo, fileData, 0)) TRACELOG(LOG_WARNING, "Failed to init font!");
|
|
||||||
|
|
||||||
|
if (stbtt_InitFont(&fontInfo, fileData, 0)) // Init font for data reading
|
||||||
|
{
|
||||||
// Calculate font scale factor
|
// Calculate font scale factor
|
||||||
float scaleFactor = stbtt_ScaleForPixelHeight(&fontInfo, (float)fontSize);
|
float scaleFactor = stbtt_ScaleForPixelHeight(&fontInfo, (float)fontSize);
|
||||||
|
|
||||||
@ -521,7 +522,7 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
|||||||
|
|
||||||
// Fill fontChars in case not provided externally
|
// Fill fontChars in case not provided externally
|
||||||
// NOTE: By default we fill charsCount consecutevely, starting at 32 (Space)
|
// NOTE: By default we fill charsCount consecutevely, starting at 32 (Space)
|
||||||
int genFontChars = false;
|
|
||||||
if (fontChars == NULL)
|
if (fontChars == NULL)
|
||||||
{
|
{
|
||||||
fontChars = (int *)RL_MALLOC(charsCount*sizeof(int));
|
fontChars = (int *)RL_MALLOC(charsCount*sizeof(int));
|
||||||
@ -585,6 +586,8 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
|||||||
TRACELOGD("Character offsetY: %i", (int)((float)ascent*scaleFactor) + chY1);
|
TRACELOGD("Character offsetY: %i", (int)((float)ascent*scaleFactor) + chY1);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "Failed to init font!");
|
||||||
|
|
||||||
RL_FREE(fileData);
|
RL_FREE(fileData);
|
||||||
if (genFontChars) RL_FREE(fontChars);
|
if (genFontChars) RL_FREE(fontChars);
|
||||||
|
|||||||
Reference in New Issue
Block a user