From e4c15140337b483c1007ecd16f5f3f08c812d3f3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Jul 2021 22:09:40 +0200 Subject: LibGfx: Use calloc() instead of malloc()+memset() Gfx::BitmapFont --- Userland/Libraries/LibGfx/BitmapFont.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Userland/Libraries/LibGfx') diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index 6a83542113..d24316ddc9 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -45,10 +45,8 @@ NonnullRefPtr BitmapFont::create(u8 glyph_height, u8 glyph_width, bo { size_t bytes_per_glyph = sizeof(u32) * glyph_height; size_t count = glyph_count_by_type(type); - auto* new_rows = static_cast(malloc(bytes_per_glyph * count)); - memset(new_rows, 0, bytes_per_glyph * count); - auto* new_widths = static_cast(malloc(count)); - memset(new_widths, 0, count); + auto* new_rows = static_cast(calloc(count, bytes_per_glyph)); + auto* new_widths = static_cast(calloc(count, 1)); return adopt_ref(*new BitmapFont("Untitled", "Untitled", new_rows, new_widths, fixed, glyph_width, glyph_height, 1, type, 0, 0, 0, 400, true)); } @@ -295,12 +293,10 @@ void BitmapFont::set_type(FontTypes type) size_t bytes_per_glyph = sizeof(u32) * glyph_height(); - auto* new_rows = static_cast(kmalloc(bytes_per_glyph * new_glyph_count)); - memset(new_rows, (unsigned)0, bytes_per_glyph * new_glyph_count); + auto* new_rows = static_cast(calloc(new_glyph_count, bytes_per_glyph)); memcpy(new_rows, m_rows, bytes_per_glyph * item_count_to_copy); - auto* new_widths = static_cast(kmalloc(new_glyph_count)); - memset(new_widths, (u8)0, new_glyph_count); + auto* new_widths = static_cast(calloc(new_glyph_count, 1)); memcpy(new_widths, m_glyph_widths, item_count_to_copy); kfree(m_rows); -- cgit v1.2.3