Skip to content
47 changes: 47 additions & 0 deletions src/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4551,6 +4551,53 @@ pub const DrawList = *opaque {
text: [*]const u8,
text_end: [*]const u8,
) void;
const AddTextArgs = struct {
font: ?Font,
font_size: f32,
wrap_width: f32 = 0,
cpu_fine_clip_rect: ?[*]const [4]f32 = null,
};
pub fn addTextExtended(
draw_list: DrawList,
pos: [2]f32,
col: u32,
comptime fmt: []const u8,
args: anytype,
add_text_args: AddTextArgs,
) void {
const txt = format(fmt, args);
addTextExtendedUnformatted(draw_list, pos, col, txt, add_text_args);
}
pub fn addTextExtendedUnformatted(
draw_list: DrawList,
pos: [2]f32,
col: u32,
txt: []const u8,
add_text_args: AddTextArgs,
) void {
zguiDrawList_AddTextExtended(
draw_list,
add_text_args.font,
add_text_args.font_size,
&pos,
col,
txt.ptr,
txt.ptr + txt.len,
add_text_args.wrap_width,
add_text_args.cpu_fine_clip_rect,
);
}
extern fn zguiDrawList_AddTextExtended(
draw_list: DrawList,
font: ?Font,
font_size: f32,
pos: *const [2]f32,
col: u32,
text: [*]const u8,
text_end: [*]const u8,
wrap_width: f32,
cpu_fine_clip_rect: ?[*]const [4]f32,
) void;
//----------------------------------------------------------------------------------------------
pub fn addPolyline(draw_list: DrawList, points: []const [2]f32, args: struct {
col: u32,
Expand Down
14 changes: 14 additions & 0 deletions src/zgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,20 @@ extern "C"
draw_list->AddText({pos[0], pos[1]}, col, text_begin, text_end);
}

ZGUI_API void zguiDrawList_AddTextExtended(
ImDrawList *draw_list,
ImFont* font,
float font_size,
const float pos[2],
ImU32 col,
const char* text_begin,
const char* text_end,
float wrap_width,
const float cpu_fine_clip_rect[][4])
{
draw_list->AddText(font, font_size, {pos[0], pos[1]}, col, text_begin, text_end, wrap_width, (const ImVec4 *)&cpu_fine_clip_rect[0][0]);
Copy link

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null pointer dereference. When 'cpu_fine_clip_rect' is null, accessing '&cpu_fine_clip_rect[0][0]' will cause undefined behavior. The cast should handle the null case properly.

Suggested change
draw_list->AddText(font, font_size, {pos[0], pos[1]}, col, text_begin, text_end, wrap_width, (const ImVec4 *)&cpu_fine_clip_rect[0][0]);
const ImVec4* clip_rect = (cpu_fine_clip_rect != nullptr) ? (const ImVec4 *)&cpu_fine_clip_rect[0][0] : nullptr;
draw_list->AddText(font, font_size, {pos[0], pos[1]}, col, text_begin, text_end, wrap_width, clip_rect);

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch bot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, will change the name, and try to apply that suggestion for clip_rect to see if that works.

Copy link
Member

@hazeycode hazeycode Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the naming is good as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought the copilot suggests to rename the struct. If the name change isn't needed, then I am going to commit the suggested fix to the null pointer dereference only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go; the suggestion is applied.

}

ZGUI_API void zguiDrawList_AddPolyline(
ImDrawList *draw_list,
const float points[][2],
Expand Down
Loading