Support nullptr char pointers #6565

Closed
opened 2023-07-01 20:11:38 +00:00 by lanyizi · 1 comment
lanyizi commented 2023-07-01 20:11:38 +00:00 (Migrated from github.com)

ocornut/imgui@655aae5911/imgui_widgets.cpp (L3874-L3877)

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?

https://github.com/ocornut/imgui/blob/655aae591157c6f1d63a06d7565fe3e64390771c/imgui_widgets.cpp#L3874-L3877 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 commented 2023-07-03 09:59:40 +00:00 (Migrated from github.com)

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!

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!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#6565
No description provided.