From 6469b94304e5c6e521054a654d3172f47b2d0019 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 2 Oct 2020 19:12:53 +0200 Subject: [PATCH] Silence memset warning. (#3505) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compiling the code as-is results in the following warning: -->8-- imgui_freetype.cpp:341:72: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct ImFontBuildSrcDataFT’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess] 341 | memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes()); | ^ imgui_freetype.cpp:302:8: note: ‘struct ImFontBuildSrcDataFT’ declared here 302 | struct ImFontBuildSrcDataFT | ^~~~~~~~~~~~~~~~~~~~ --8<-- This is caused by presence of ImVector<> directly in ImFontBuildSrcDataFT data structure, as well as in the child ImBitVector. Since ImVector<> has a constructor, the compiler infers that initialization by memset is not valid. Such initialization is not a bug, however, as the default ImVector<> ctor just sets the structure data members to 0, which is exactly what the memset does. Casting the data structure address to void* pointer silences this warning. --- misc/freetype/imgui_freetype.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 3d62dc4b6..412411a94 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -338,8 +338,8 @@ bool ImFontAtlasBuildWithFreeType(FT_Library ft_library, ImFontAtlas* atlas, uns ImVector dst_tmp_array; src_tmp_array.resize(atlas->ConfigData.Size); dst_tmp_array.resize(atlas->Fonts.Size); - memset(src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes()); - memset(dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes()); + memset((void*)src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes()); + memset((void*)dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes()); // 1. Initialize font loading structure, check font data validity for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)