Skip to content

Null-terminate label, hint and name strings in manual wrappers - #534

Open
armadavalor wants to merge 1 commit into
ImGuiNET:masterfrom
armadavalor:fix-null-terminate-manual-strings
Open

armadavalor wants to merge 1 commit into
ImGuiNET:masterfrom
armadavalor:fix-null-terminate-manual-strings

Conversation

@armadavalor

Copy link
Copy Markdown

The hand-written wrappers in ImGui.Manual.cs / ImGui.Manual.ReadOnlySpan.cs (InputText, InputTextMultiline, InputTextWithHint, InputText(byte[]), Begin) encode the label/hint/name into a buffer of byteCount + 1 bytes but never write the trailing \0.

When the string fits under Util.StackAllocationSizeLimit this happens to work because stackalloc memory is zeroed, but for longer strings the buffer comes from Util.Allocate (Marshal.AllocHGlobal), which is uninitialized, so ImGui reads past the end of the label and renders garbage (as shown in the issue).

This adds the terminator explicitly after each Util.GetUtf8 call, the same way the generated code already does (native_label[native_label_offset] = 0;). The input text buffers were already cleared with InitBlockUnaligned, so they are unchanged.

Built src/ImGui.NET locally (0 warnings, 0 errors).

Closes #502

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Utf8 strings are not null-terminated

1 participant