Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Uneven Prankster committed Jan 26, 2025
1 parent b4583ce commit c7f7fa9
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/rtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2228,32 +2228,32 @@ static Font LoadBMFont(const char *fileName)
imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i]));

PixelFormat format = imFonts[i].format;
if (format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8)
continue;
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
Image imFontAlpha = {
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),
.width = imFonts[i].width,
.height = imFonts[i].height,
.mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
};
int stride = 1;
if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8){
stride = 3;
}else if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8){
stride = 4;
}
for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++)
{
((unsigned char *)(imFontAlpha.data))[p] = 0xff;
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi * stride];
}
UnloadImage(imFonts[i]);
if (format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8)
continue;
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
Image imFontAlpha = {
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),

Check failure

Code scanning / CodeQL

Uncontrolled allocation size High

This allocation size is derived from
user input (string read by fread)
and could allocate arbitrary amounts of memory.
.width = imFonts[i].width,
.height = imFonts[i].height,
.mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
};
int stride = 1;
if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8){
stride = 3;
}else if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8){
stride = 4;
}
for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++)
{
((unsigned char *)(imFontAlpha.data))[p] = 0xff;
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi * stride];
}
UnloadImage(imFonts[i]);
imFonts[i] = imFontAlpha;
}

Expand Down

0 comments on commit c7f7fa9

Please sign in to comment.