Misc: fixes zealous MSVC static analyzer warnings + make GetInputSourceName(), GetMouseSourceName() a little more tolerant. (#8876)

This commit is contained in:
ocornut
2025-08-11 11:01:13 +02:00
parent 47c41483bd
commit 1c57dc21c2
3 changed files with 10 additions and 3 deletions

View File

@@ -10175,13 +10175,17 @@ void ImGui::SetNextFrameWantCaptureMouse(bool want_capture_mouse)
static const char* GetInputSourceName(ImGuiInputSource source) static const char* GetInputSourceName(ImGuiInputSource source)
{ {
const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad" }; const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad" };
IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT && source >= 0 && source < ImGuiInputSource_COUNT); IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT);
if (source < 0 || source >= ImGuiInputSource_COUNT)
return "Unknown";
return input_source_names[source]; return input_source_names[source];
} }
static const char* GetMouseSourceName(ImGuiMouseSource source) static const char* GetMouseSourceName(ImGuiMouseSource source)
{ {
const char* mouse_source_names[] = { "Mouse", "TouchScreen", "Pen" }; const char* mouse_source_names[] = { "Mouse", "TouchScreen", "Pen" };
IM_ASSERT(IM_ARRAYSIZE(mouse_source_names) == ImGuiMouseSource_COUNT && source >= 0 && source < ImGuiMouseSource_COUNT); IM_ASSERT(IM_ARRAYSIZE(mouse_source_names) == ImGuiMouseSource_COUNT);
if (source < 0 || source >= ImGuiMouseSource_COUNT)
return "Unknown";
return mouse_source_names[source]; return mouse_source_names[source];
} }
static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e) static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e)
@@ -14157,6 +14161,7 @@ static void ImGui::NavUpdateWindowingApplyFocus(ImGuiWindow* apply_focus_window)
SetNavCursorVisibleAfterMove(); SetNavCursorVisibleAfterMove();
ClosePopupsOverWindow(apply_focus_window, false); ClosePopupsOverWindow(apply_focus_window, false);
FocusWindow(apply_focus_window, ImGuiFocusRequestFlags_RestoreFocusedChild); FocusWindow(apply_focus_window, ImGuiFocusRequestFlags_RestoreFocusedChild);
IM_ASSERT(g.NavWindow != NULL);
apply_focus_window = g.NavWindow; apply_focus_window = g.NavWindow;
if (apply_focus_window->NavLastIds[0] == 0) if (apply_focus_window->NavLastIds[0] == 0)
NavInitWindow(apply_focus_window, false); NavInitWindow(apply_focus_window, false);

View File

@@ -4372,6 +4372,7 @@ ImTextureRect* ImFontAtlasPackGetRectSafe(ImFontAtlas* atlas, ImFontAtlasRectId
if (atlas->Builder == NULL) if (atlas->Builder == NULL)
ImFontAtlasBuildInit(atlas); ImFontAtlasBuildInit(atlas);
ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder; ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
IM_MSVC_WARNING_SUPPRESS(28182); // Static Analysis false positive "warning C28182: Dereferencing NULL pointer 'builder'"
if (index_idx >= builder->RectsIndex.Size) if (index_idx >= builder->RectsIndex.Size)
return NULL; return NULL;
ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx]; ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx];

View File

@@ -8883,6 +8883,7 @@ void ImGui::EndMenuBar()
PopClipRect(); PopClipRect();
PopID(); PopID();
IM_MSVC_WARNING_SUPPRESS(6011); // Static Analysis false positive "warning C6011: Dereferencing NULL pointer 'window'"
window->DC.MenuBarOffset.x = window->DC.CursorPos.x - window->Pos.x; // Save horizontal position so next append can reuse it. This is kinda equivalent to a per-layer CursorPos. window->DC.MenuBarOffset.x = window->DC.CursorPos.x - window->Pos.x; // Save horizontal position so next append can reuse it. This is kinda equivalent to a per-layer CursorPos.
// FIXME: Extremely confusing, cleanup by (a) working on WorkRect stack system (b) not using a Group confusingly here. // FIXME: Extremely confusing, cleanup by (a) working on WorkRect stack system (b) not using a Group confusingly here.