Skip to content

Commit

Permalink
fix: C null values causing panic if prompt or path input is canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 29, 2024
1 parent 080b5b0 commit 8ea6ae8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ pub const osdialog_color = extern struct { r: u8, g: u8, b: u8, a: u8 };
pub const osdialog_filters = extern struct {};

pub extern fn osdialog_message(level: c_int, buttons: c_int, message: [*c]const u8) c_int;
pub extern fn osdialog_prompt(level: c_int, message: [*c]const u8, text: [*c]const u8) [*c]u8;
pub extern fn osdialog_prompt(level: c_int, message: [*c]const u8, text: [*c]const u8) ?*anyopaque;
pub extern fn osdialog_color_picker(color: *osdialog_color, opacity: c_int) c_int;
pub extern fn osdialog_file(action: c_int, path: [*c]const u8, filename: [*c]const u8, filters: ?*osdialog_filters) [*c]u8;
pub extern fn osdialog_file(action: c_int, path: [*c]const u8, filename: [*c]const u8, filters: ?*osdialog_filters) ?*anyopaque;

pub fn toZString(allocator: std.mem.Allocator, c_str_opt: ?[*c]u8) ?[:0]u8 {
const c_string = c_str_opt orelse return null;
pub fn toZString(allocator: std.mem.Allocator, c_str_opt: ?*anyopaque) ?[:0]u8 {
const ptr = c_str_opt orelse return null;
const c_string: [*c]u8 = @ptrCast(ptr);
defer std.c.free(c_string);
const z_string: [:0]u8 = std.mem.span(c_string);
return allocator.dupeZ(u8, z_string) catch return null;
Expand Down

0 comments on commit 8ea6ae8

Please sign in to comment.