mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-08 07:25:54 +01:00
Fix integer overflow in size calculations
This commit is contained in:
parent
2859f6723c
commit
7d41093d4f
@ -16737,7 +16737,7 @@ static const char* FormatTextureRefForDebugDisplay(char* buf, int buf_size, ImTe
|
||||
char* buf_end = buf + buf_size;
|
||||
if (tex_ref._TexData != NULL)
|
||||
buf_p += ImFormatString(buf_p, buf_end - buf_p, "#%03d: ", tex_ref._TexData->UniqueID);
|
||||
ImFormatString(buf_p, buf_end - buf_p, "0x%X", ImGui::DebugTextureIDToU64(tex_ref.GetTexID()));
|
||||
ImFormatString(buf_p, buf_end - buf_p, "0x%llX", (unsigned long long)ImGui::DebugTextureIDToU64(tex_ref.GetTexID()));
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
@ -3722,9 +3722,9 @@ void ImTextureData::Create(ImTextureFormat format, int w, int h)
|
||||
Height = h;
|
||||
BytesPerPixel = ImTextureDataGetFormatBytesPerPixel(format);
|
||||
UseColors = false;
|
||||
Pixels = (unsigned char*)IM_ALLOC(Width * Height * BytesPerPixel);
|
||||
Pixels = (unsigned char*)IM_ALLOC((size_t)Width * (size_t)Height * (size_t)BytesPerPixel);
|
||||
IM_ASSERT(Pixels != NULL);
|
||||
memset(Pixels, 0, Width * Height * BytesPerPixel);
|
||||
memset(Pixels, 0, (size_t)Width * (size_t)Height * (size_t)BytesPerPixel);
|
||||
UsedRect.x = UsedRect.y = UsedRect.w = UsedRect.h = 0;
|
||||
UpdateRect.x = UpdateRect.y = (unsigned short)~0;
|
||||
UpdateRect.w = UpdateRect.h = 0;
|
||||
@ -4215,7 +4215,7 @@ void ImFontAtlasTextureBlockCopy(ImTextureData* src_tex, int src_x, int src_y, I
|
||||
IM_ASSERT(dst_x >= 0 && dst_x + w <= dst_tex->Width);
|
||||
IM_ASSERT(dst_y >= 0 && dst_y + h <= dst_tex->Height);
|
||||
for (int y = 0; y < h; y++)
|
||||
memcpy(dst_tex->GetPixelsAt(dst_x, dst_y + y), src_tex->GetPixelsAt(src_x, src_y + y), w * dst_tex->BytesPerPixel);
|
||||
memcpy(dst_tex->GetPixelsAt(dst_x, dst_y + y), src_tex->GetPixelsAt(src_x, src_y + y), (size_t)w * (size_t)dst_tex->BytesPerPixel);
|
||||
}
|
||||
|
||||
void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex, int x, int y, int w, int h)
|
||||
@ -6343,9 +6343,9 @@ static bool ImGui_ImplStbTrueType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontC
|
||||
// Render
|
||||
stbtt_GetGlyphBitmapBox(&bd_font_data->FontInfo, glyph_index, scale_for_raster_x, scale_for_raster_y, &x0, &y0, &x1, &y1);
|
||||
ImFontAtlasBuilder* builder = atlas->Builder;
|
||||
builder->TempBuffer.resize(w * h * 1);
|
||||
builder->TempBuffer.resize((size_t)w * (size_t)h);
|
||||
unsigned char* bitmap_pixels = builder->TempBuffer.Data;
|
||||
memset(bitmap_pixels, 0, w * h * 1);
|
||||
memset(bitmap_pixels, 0, (size_t)w * (size_t)h);
|
||||
|
||||
// Render with oversampling
|
||||
// (those functions conveniently assert if pixels are not cleared, which is another safety layer)
|
||||
|
||||
@ -3747,7 +3747,7 @@ STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info
|
||||
if (yoff ) *yoff = iy0;
|
||||
|
||||
if (gbm.w && gbm.h) {
|
||||
gbm.pixels = (unsigned char *) STBTT_malloc(gbm.w * gbm.h, info->userdata);
|
||||
gbm.pixels = (unsigned char *) STBTT_malloc((size_t)gbm.w * (size_t)gbm.h, info->userdata);
|
||||
if (gbm.pixels) {
|
||||
gbm.stride = gbm.w;
|
||||
|
||||
@ -3830,7 +3830,7 @@ static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, // fo
|
||||
f.userdata = NULL;
|
||||
if (!stbtt_InitFont(&f, data, offset))
|
||||
return -1;
|
||||
STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels
|
||||
STBTT_memset(pixels, 0, (size_t)pw * (size_t)ph); // background of 0 around pixels
|
||||
x=y=1;
|
||||
bottom_y = 1;
|
||||
|
||||
@ -3989,7 +3989,7 @@ STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, in
|
||||
stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes);
|
||||
|
||||
if (pixels)
|
||||
STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels
|
||||
STBTT_memset(pixels, 0, (size_t)pw * (size_t)ph); // background of 0 around pixels
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -4616,8 +4616,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
||||
float *precompute;
|
||||
stbtt_vertex *verts;
|
||||
int num_verts = stbtt_GetGlyphShape(info, glyph, &verts);
|
||||
data = (unsigned char *) STBTT_malloc(w * h, info->userdata);
|
||||
precompute = (float *) STBTT_malloc(num_verts * sizeof(float), info->userdata);
|
||||
data = (unsigned char *) STBTT_malloc((size_t)w * (size_t)h, info->userdata);
|
||||
precompute = (float *) STBTT_malloc((size_t)num_verts * sizeof(float), info->userdata);
|
||||
|
||||
for (i=0,j=num_verts-1; i < num_verts; j=i++) {
|
||||
if (verts[i].type == STBTT_vline) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user