]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - ft2.c
Fix an error detected by -Wnarrowing (~0 narrowing to unsigned char,
[xonotic/darkplaces.git] / ft2.c
diff --git a/ft2.c b/ft2.c
index 1711aded978e8985cc64632adc88c40210a463bc..bc9544f2153f6f345083ce2ea35f47d000e714e0 100644 (file)
--- a/ft2.c
+++ b/ft2.c
@@ -629,6 +629,11 @@ static qboolean Font_LoadFile(const char *name, int _face, ft2_settings_t *setti
        font->settings = settings;
 
        namelen = strlen(name);
+       if (namelen + 5 > sizeof(filename))
+       {
+               Con_Printf("WARNING: too long font name. Cannot load this.\n");
+               return false;
+       }
 
        // try load direct file
        memcpy(filename, name, namelen+1);
@@ -698,7 +703,7 @@ static qboolean Font_LoadFile(const char *name, int _face, ft2_settings_t *setti
                        Con_Printf("Failed to add attachment %u to %s\n", (unsigned)i, font->name);
        }
 
-       memcpy(font->name, name, namelen+1);
+       strlcpy(font->name, name, sizeof(font->name));
        font->image_font = false;
        font->has_kerning = !!(((FT_Face)(font->face))->face_flags & FT_FACE_FLAG_KERNING);
        return true;