Fix possible segfault in Font

This commit is contained in:
MrLetsplay 2023-09-16 17:03:15 +02:00
parent dec6cdec3f
commit 656603f439
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg

View File

@ -249,9 +249,9 @@ CharacterBlock Font::generateCharacterBlock(unsigned int block) {
int row = c / KEK_FONT_BITMAP_WIDTH_BLOCKS; int row = c / KEK_FONT_BITMAP_WIDTH_BLOCKS;
// TODO: handle wide characters more gracefully // TODO: handle wide characters more gracefully
for(unsigned int r = 0; r < std::min(64u, face->glyph->bitmap.rows); r++) { for(unsigned int r = 0; r < std::min((unsigned int) KEK_FONT_RESOLUTION, face->glyph->bitmap.rows); r++) {
size_t offset = row * KEK_FONT_RESOLUTION * KEK_FONT_BITMAP_WIDTH + col * KEK_FONT_RESOLUTION + r * KEK_FONT_BITMAP_WIDTH; size_t offset = row * KEK_FONT_RESOLUTION * KEK_FONT_BITMAP_WIDTH + col * KEK_FONT_RESOLUTION + r * KEK_FONT_BITMAP_WIDTH;
size_t len = face->glyph->bitmap.width; size_t len = glm::min((unsigned int) KEK_FONT_RESOLUTION, face->glyph->bitmap.width);
memcpy(textureBytes + offset, memcpy(textureBytes + offset,
face->glyph->bitmap.buffer + r * face->glyph->bitmap.width, face->glyph->bitmap.buffer + r * face->glyph->bitmap.width,
len); len);