[GH-ISSUE #463] WrapBreak u16 overflows #123

Closed
opened 2026-03-02 23:44:42 +03:00 by kerem · 0 comments
Owner

Originally created by @simonklee on GitHub (Jan 2, 2026).
Original GitHub issue: https://github.com/anomalyco/opentui/issues/463

I noticed that WrapBreak uses u16 when trying to run the TextBuffer Wrapping benchmark for long lines. The benchmark in bench/text-buffer-view_bench.zig generates a 2MB single-line test case via generateLargeTextSingleLine(2 * 1024 * 1024), which overflows the u16 fields:

cd packages/core/src/zig
zig build bench -- --filter "TextBuffer Wrapping"

But in debug mode:

thread 78949 panic: integer cast truncated bits
/home/simon/insmo.com/opentui/packages/core/src/zig/utf8.zig:237:36: 0x1170226 in findWrapBreaks (opentui-bench)
                    .byte_offset = @intCast(pos + bit_pos),
                                   ^

In ReleaseFast mode values are silently truncate, creating incorrect wrap positions.

I think a simple fix is to widen to a u32:

pub const WrapBreak = struct {
    byte_offset: u32,
    char_offset: u32,
};
Originally created by @simonklee on GitHub (Jan 2, 2026). Original GitHub issue: https://github.com/anomalyco/opentui/issues/463 I noticed that `WrapBreak` uses `u16` when trying to run the TextBuffer Wrapping benchmark for long lines. The benchmark in `bench/text-buffer-view_bench.zig` generates a 2MB single-line test case via `generateLargeTextSingleLine(2 * 1024 * 1024)`, which overflows the `u16` fields: ```bash cd packages/core/src/zig zig build bench -- --filter "TextBuffer Wrapping" ``` But in debug mode: ``` thread 78949 panic: integer cast truncated bits /home/simon/insmo.com/opentui/packages/core/src/zig/utf8.zig:237:36: 0x1170226 in findWrapBreaks (opentui-bench) .byte_offset = @intCast(pos + bit_pos), ^ ``` In ReleaseFast mode values are silently truncate, creating incorrect wrap positions. I think a simple fix is to widen to a `u32`: ```zig pub const WrapBreak = struct { byte_offset: u32, char_offset: u32, }; ```
kerem closed this issue 2026-03-02 23:44:42 +03:00
Sign in to join this conversation.
No milestone
No project
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
starred/opentui#123
No description provided.