From 6abe65aac686593d6fa25ba4734445f3f8fcd49f Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 18 Mar 2026 18:57:02 +0100 Subject: [PATCH] InputText: amend fix to avoid PVS-Studio sort of rightful false positive. Amend f4c2f50. (#9174) Checking for state != NULL in the two othr functions where state is already deferenced was misleading. imgui_widgets.cpp:4496:1: error: V595 The 'state' pointer was utilized before it was verified against nullptr. Check lines: 4496, 4500. imgui_widgets.cpp:5273:1: error: V595 The 'state' pointer was utilized before it was verified against nullptr. Check lines: 5273, 5289. --- imgui_widgets.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index cebe73b8b..8a2ab9f31 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4402,6 +4402,7 @@ void ImGui::PopPasswordFont() // Return false to discard a character. static bool InputTextFilterCharacter(ImGuiContext* ctx, ImGuiInputTextState* state, unsigned int* p_char, ImGuiInputTextCallback callback, void* user_data, bool input_source_is_clipboard) { + IM_ASSERT(state != NULL); unsigned int c = *p_char; ImGuiInputTextFlags flags = state->Flags; @@ -4497,7 +4498,7 @@ static bool InputTextFilterCharacter(ImGuiContext* ctx, ImGuiInputTextState* sta callback_data.Flags = flags; callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; callback_data.EventChar = (ImWchar)c; - callback_data.EventActivated = (state && g.ActiveId == state->ID && g.ActiveIdIsJustActivated); + callback_data.EventActivated = (g.ActiveId == state->ID && g.ActiveIdIsJustActivated); callback_data.UserData = user_data; if (callback(&callback_data) != 0) return false; @@ -5286,7 +5287,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ callback_data.ID = id; callback_data.Flags = flags; callback_data.EventFlag = event_flag; - callback_data.EventActivated = (state && g.ActiveId == state->ID && g.ActiveIdIsJustActivated); + callback_data.EventActivated = (g.ActiveId == state->ID && g.ActiveIdIsJustActivated); callback_data.UserData = callback_user_data; // FIXME-OPT: Undo stack reconcile needs a backup of the data until we rework API, see #7925