Skip to content

Commit 8f43b53

Browse files
committed
fix: use named field instead of offset
1 parent 89b1440 commit 8f43b53

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/init.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ffi.cdef [[
2424
typedef struct { const char *message; int klass; } git_error;
2525

2626
/* opaque options structs — sized to match the ABI, initialized via _init */
27-
typedef struct { char _[416]; } git_clone_options;
27+
typedef struct { char _[376]; const char *checkout_branch; char _rest[32]; } git_clone_options;
2828
typedef struct { char _[376]; } git_submodule_update_options;
2929

3030
const git_error *git_error_last(void);
@@ -315,9 +315,7 @@ function git2.clone(url, path, branch)
315315
if branch then
316316
local o = ffi.new("git_clone_options")
317317
lib.git_clone_options_init(o, 1)
318-
-- checkout_branch is a const char* at offset 376; cast to set it
319-
local ptr = ffi.cast("const char**", ffi.cast("char*", o) + 376)
320-
ptr[0] = branch
318+
o.checkout_branch = branch
321319
opts = o
322320
end
323321
check(lib.git_clone(rp, url, path, opts))

0 commit comments

Comments
 (0)