From 54805fd22a8b7dac4bcf206c5cd8f28ecb217c86 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 5 Oct 2015 14:13:24 +0200 Subject: [PATCH] InputText: fixed crash when passing a buf_size==0 (which can be of use for read-only selectable text boxes) (#360) --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c70479601..853c0878f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7123,8 +7123,8 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar) // From the moment we focused we are ignoring the content of 'buf' const int prev_len_w = edit_state.CurLenW; - edit_state.Text.resize(buf_size); // wchar count <= utf-8 count - edit_state.InitialText.resize(buf_size); // utf-8 + edit_state.Text.resize(buf_size+1); // wchar count <= utf-8 count. we use +1 to make sure that .Data isn't NULL so it doesn't crash. + edit_state.InitialText.resize(buf_size+1); // utf-8. we use +1 to make sure that .Data isn't NULL so it doesn't crash. ImFormatString(edit_state.InitialText.Data, edit_state.InitialText.Size, "%s", buf); const char* buf_end = NULL; edit_state.CurLenW = ImTextStrFromUtf8(edit_state.Text.Data, edit_state.Text.Size, buf, NULL, &buf_end);