From 20d415e939081502b5c42da2ea5c1a06d6d8c530 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 24 Jun 2021 15:13:21 +0200 Subject: [PATCH] FIx static analysers warnings and disable false positives. --- .github/workflows/static-analysis.yml | 2 +- backends/imgui_impl_dx9.cpp | 8 ++++---- backends/imgui_impl_win32.cpp | 2 ++ imgui_widgets.cpp | 2 +- misc/freetype/imgui_freetype.cpp | 13 ++++++++----- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index d3b7d50b..f3e6b2d1 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -43,7 +43,7 @@ jobs: cd examples/example_null pvs-studio-analyzer trace -- make WITH_EXTRA_WARNINGS=1 pvs-studio-analyzer analyze -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log - plog-converter -a 'GA:1,2;OP:1' -t errorfile -w pvs-studio.log + plog-converter -a 'GA:1,2;OP:1' -d V1071 -t errorfile -w pvs-studio.log Discord-CI: runs-on: ubuntu-18.04 diff --git a/backends/imgui_impl_dx9.cpp b/backends/imgui_impl_dx9.cpp index c874516c..fd20e6b6 100644 --- a/backends/imgui_impl_dx9.cpp +++ b/backends/imgui_impl_dx9.cpp @@ -5,7 +5,7 @@ // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. -// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. +// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs @@ -278,8 +278,8 @@ static bool ImGui_ImplDX9_CreateFontsTexture() #ifndef IMGUI_USE_BGRA_PACKED_COLOR if (io.Fonts->TexPixelsUseColors) { - ImU32* dst_start = (ImU32*)ImGui::MemAlloc(width * height * bytes_per_pixel); - for (ImU32* src = (ImU32*)pixels, *dst = dst_start, *dst_end = dst_start + width * height; dst < dst_end; src++, dst++) + ImU32* dst_start = (ImU32*)ImGui::MemAlloc((size_t)width * height * bytes_per_pixel); + for (ImU32* src = (ImU32*)pixels, *dst = dst_start, *dst_end = dst_start + (size_t)width * height; dst < dst_end; src++, dst++) *dst = IMGUI_COL_TO_DX9_ARGB(*src); pixels = (unsigned char*)dst_start; } @@ -293,7 +293,7 @@ static bool ImGui_ImplDX9_CreateFontsTexture() if (g_FontTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK) return false; for (int y = 0; y < height; y++) - memcpy((unsigned char*)tex_locked_rect.pBits + tex_locked_rect.Pitch * y, pixels + (width * bytes_per_pixel) * y, (width * bytes_per_pixel)); + memcpy((unsigned char*)tex_locked_rect.pBits + (size_t)tex_locked_rect.Pitch * y, pixels + (size_t)width * bytes_per_pixel * y, (size_t)width * bytes_per_pixel); g_FontTexture->UnlockRect(0); // Store our identifier diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index f2425f06..bd4eddfd 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -420,6 +420,8 @@ static BOOL _IsWindowsVersionOrGreater(WORD major, WORD minor, WORD) if (RtlVerifyVersionInfoFn == NULL) if (HMODULE ntdllModule = ::GetModuleHandleA("ntdll.dll")) RtlVerifyVersionInfoFn = (PFN_RtlVerifyVersionInfo)GetProcAddress(ntdllModule, "RtlVerifyVersionInfo"); + if (RtlVerifyVersionInfoFn == NULL) + return FALSE; RTL_OSVERSIONINFOEXW versionInfo = { }; ULONGLONG conditionMask = 0; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ce20b369..aee3242b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -8119,7 +8119,7 @@ void ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, else if (unsaved_marker_visible) { const ImRect bullet_bb(button_pos, button_pos + ImVec2(button_sz, button_sz) + g.Style.FramePadding * 2.0f); - RenderBullet(bullet_bb.GetCenter()); + RenderBullet(draw_list, bullet_bb.GetCenter(), GetColorU32(ImGuiCol_Text)); } // This is all rather complicated diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index e6221f4b..2538f20a 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -41,7 +41,8 @@ #include FT_SYNTHESIS_H // #ifdef _MSC_VER -#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) +#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) +#pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). #endif #if defined(__GNUC__) @@ -600,13 +601,15 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight); if (src_load_color) { - atlas->TexPixelsRGBA32 = (unsigned int*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight * 4); - memset(atlas->TexPixelsRGBA32, 0, atlas->TexWidth * atlas->TexHeight * 4); + size_t tex_size = (size_t)atlas->TexWidth * atlas->TexHeight * 4; + atlas->TexPixelsRGBA32 = (unsigned int*)IM_ALLOC(tex_size); + memset(atlas->TexPixelsRGBA32, 0, tex_size); } else { - atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight); - memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight); + size_t tex_size = (size_t)atlas->TexWidth * atlas->TexHeight * 1; + atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(tex_size); + memset(atlas->TexPixelsAlpha8, 0, tex_size); } // 8. Copy rasterized font characters back into the main texture