]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - ft2.c
Fix rogue mission pack (Dissolution of Eternity) plasma launcher which
[xonotic/darkplaces.git] / ft2.c
diff --git a/ft2.c b/ft2.c
index 1711aded978e8985cc64632adc88c40210a463bc..e30c22e6969f3d26dc73bfd0654c8567585be675 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;
@@ -1510,35 +1515,35 @@ static qboolean Font_LoadMap(ft2_font_t *font, ft2_font_map_t *mapstart, Uchar _
                                        dst += bytesPerPixel - 1; // shift to alpha byte
                                        for (x = 0; x < bmp->width; x += 8)
                                        {
-                                               unsigned char ch = *src++;
-                                               *dst = 255 * !!((ch & 0x80) >> 7); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x40) >> 6); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x20) >> 5); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x10) >> 4); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x08) >> 3); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x04) >> 2); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x02) >> 1); dst += bytesPerPixel;
-                                               *dst = 255 * !!((ch & 0x01) >> 0); dst += bytesPerPixel;
+                                               unsigned char c = *src++;
+                                               *dst = 255 * !!((c & 0x80) >> 7); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x40) >> 6); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x20) >> 5); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x10) >> 4); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x08) >> 3); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x04) >> 2); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x02) >> 1); dst += bytesPerPixel;
+                                               *dst = 255 * !!((c & 0x01) >> 0); dst += bytesPerPixel;
                                        }
                                        break;
                                case FT_PIXEL_MODE_GRAY2:
                                        dst += bytesPerPixel - 1; // shift to alpha byte
                                        for (x = 0; x < bmp->width; x += 4)
                                        {
-                                               unsigned char ch = *src++;
-                                               *dst = ( ((ch & 0xA0) >> 6) * 0x55 ); ch <<= 2; dst += bytesPerPixel;
-                                               *dst = ( ((ch & 0xA0) >> 6) * 0x55 ); ch <<= 2; dst += bytesPerPixel;
-                                               *dst = ( ((ch & 0xA0) >> 6) * 0x55 ); ch <<= 2; dst += bytesPerPixel;
-                                               *dst = ( ((ch & 0xA0) >> 6) * 0x55 ); ch <<= 2; dst += bytesPerPixel;
+                                               unsigned char c = *src++;
+                                               *dst = ( ((c & 0xA0) >> 6) * 0x55 ); c <<= 2; dst += bytesPerPixel;
+                                               *dst = ( ((c & 0xA0) >> 6) * 0x55 ); c <<= 2; dst += bytesPerPixel;
+                                               *dst = ( ((c & 0xA0) >> 6) * 0x55 ); c <<= 2; dst += bytesPerPixel;
+                                               *dst = ( ((c & 0xA0) >> 6) * 0x55 ); c <<= 2; dst += bytesPerPixel;
                                        }
                                        break;
                                case FT_PIXEL_MODE_GRAY4:
                                        dst += bytesPerPixel - 1; // shift to alpha byte
                                        for (x = 0; x < bmp->width; x += 2)
                                        {
-                                               unsigned char ch = *src++;
-                                               *dst = ( ((ch & 0xF0) >> 4) * 0x11); dst += bytesPerPixel;
-                                               *dst = ( ((ch & 0x0F) ) * 0x11); dst += bytesPerPixel;
+                                               unsigned char c = *src++;
+                                               *dst = ( ((c & 0xF0) >> 4) * 0x11); dst += bytesPerPixel;
+                                               *dst = ( ((c & 0x0F) ) * 0x11); dst += bytesPerPixel;
                                        }
                                        break;
                                case FT_PIXEL_MODE_GRAY: