Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nullptr char pointers #6565

Closed
lanyizi opened this issue Jul 1, 2023 · 1 comment
Closed

Support nullptr char pointers #6565

lanyizi opened this issue Jul 1, 2023 · 1 comment

Comments

@lanyizi
Copy link

lanyizi commented Jul 1, 2023

imgui/imgui_widgets.cpp

Lines 3874 to 3877 in 655aae5

void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
{
const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0;
const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)strlen(new_text);

An empty std::string_view returns nullptr from its data() and 0 from its size().
One might expect that by calling Insert(p, view.data(), view.size()) should work, but when view is empty, this actually leads into dereferencing a null pointer because of strlen(new_text).

Could Dear ImGui support null char* in its API?

ocornut added a commit that referenced this issue Jul 3, 2023
…L) range, in order to conform to common idioms. (#6565, #6566, #3615)
@ocornut
Copy link
Owner

ocornut commented Jul 3, 2023

Hello,
Thanks for reporting. This is analogous to #3615 we did for TextUnformatted().
I have pushed a fix 6417268.
Proposed fix #6566 would erroneously silently not-crash on (NULL,non-NULL) combo so I am opting for a == test there.
Thank you!

@ocornut ocornut closed this as completed Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants