mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-18 01:14:19 +00:00
InputText: sanity checks to e.g. detect non zero-terminated buffers + removed a redundant strlen() call during activation.
This commit is contained in:
parent
ae839620b9
commit
9b0e61aaaa
2 changed files with 6 additions and 1 deletions
|
|
@ -4389,6 +4389,7 @@ void ImGui::InputTextDeactivateHook(ImGuiID id)
|
|||
else
|
||||
{
|
||||
IM_ASSERT(state->TextA.Data != 0);
|
||||
IM_ASSERT(state->TextA[state->TextLen] == 0);
|
||||
g.InputTextDeactivatedState.TextA.resize(state->TextLen + 1);
|
||||
memcpy(g.InputTextDeactivatedState.TextA.Data, state->TextA.Data, state->TextLen + 1);
|
||||
}
|
||||
|
|
@ -4519,6 +4520,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
if (init_reload_from_user_buf)
|
||||
{
|
||||
int new_len = (int)strlen(buf);
|
||||
IM_ASSERT(new_len + 1 <= buf_size && "Is your input buffer properly zero-terminated?");
|
||||
state->WantReloadUserBuf = false;
|
||||
InputTextReconcileUndoState(state, state->TextA.Data, state->TextLen, buf, new_len);
|
||||
state->TextA.resize(buf_size + 1); // we use +1 to make sure that .Data is always pointing to at least an empty string.
|
||||
|
|
@ -4540,6 +4542,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
// Take a copy of the initial buffer value.
|
||||
// From the moment we focused we are normally ignoring the content of 'buf' (unless we are in read-only mode)
|
||||
const int buf_len = (int)strlen(buf);
|
||||
IM_ASSERT(buf_len + 1 <= buf_size && "Is your input buffer properly zero-terminated?");
|
||||
state->TextToRevertTo.resize(buf_len + 1); // UTF-8. we use +1 to make sure that .Data is always pointing to at least an empty string.
|
||||
memcpy(state->TextToRevertTo.Data, buf, buf_len + 1);
|
||||
|
||||
|
|
@ -4551,7 +4554,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
|
||||
// Start edition
|
||||
state->ID = id;
|
||||
state->TextLen = (int)strlen(buf);
|
||||
state->TextLen = buf_len;
|
||||
if (!is_readonly)
|
||||
{
|
||||
state->TextA.resize(buf_size + 1); // we use +1 to make sure that .Data is always pointing to at least an empty string.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue