mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
pd_text_delete_ex - Use-after-free: in same-line branch, pd_text_delete_line(end_y) was followed by pd_text_line_set_length / pd_text_update_line_size on the freed line. Now returns immediately after delete_line in that path. - Off-by-one: cross-line merge used j = end_x + 1, dropping one char when end_x is mid-line. Now j = end_x, and the line-tail special case resets end_x to 0 explicitly. - OOB read: prev_line = text->lines[char_y - 1] without bounds check. Now guarded with char_y > 0 ? ... : NULL. - Memory leak: chars in the deleted range were never freed and ownership transfer between lines could double-free on delete_line. pd_text_line_set_length - realloc-grown slots were not zeroed, leaving uninitialized pointer values that could be misread as live pd_char_t *. pd_text_dump - col was not reset when advancing to the next line, so output was truncated at the first line's length. - Did not emit the line-ending characters recorded in line->eol, so multi-line text was concatenated without separators. Helpers - Extract pd_text_line_erase / pd_text_line_move to centralize char ownership transfer; reused in pd_text_merge_line. Tests - Add lib/pandagl/tests/test_text_edit.c with 11 cases covering the original crash scenarios (backspace at last empty line, delete at line end), boundary cases, and dump behavior. Closes #270