summaryrefslogtreecommitdiff
path: root/blob.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2016-08-27 21:02:47 +0200
committerGitHub <[email protected]>2016-08-27 21:02:47 +0200
commite1467c0641eaf7d3f3c9f5df87b0453747c46ad8 (patch)
treef1800920846b36d1f302028c015ff027fe8eb60a /blob.go
parent0703dae9b29c1c47d67f2388342b7a0bc87f55b8 (diff)
parent5c678353faa4f180ee4ad8a5e58ca71e093cf757 (diff)
Merge pull request #337 from libgit2/cmn/go16-blob-pointer
Work around the finnicky 1.6 CGo pointer checks
Diffstat (limited to 'blob.go')
-rw-r--r--blob.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/blob.go b/blob.go
index 1a86e60..8b3e94f 100644
--- a/blob.go
+++ b/blob.go
@@ -37,15 +37,24 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
defer runtime.UnlockOSThread()
var id C.git_oid
- var ptr unsafe.Pointer
+ var size C.size_t
+ // Go 1.6 added some increased checking of passing pointer to
+ // C, but its check depends on its expectations of waht we
+ // pass to the C function, so unless we take the address of
+ // its contents at the call site itself, it can fail when
+ // 'data' is a slice of a slice.
+ //
+ // When we're given an empty slice, create a dummy one where 0
+ // isn't out of bounds.
if len(data) > 0 {
- ptr = unsafe.Pointer(&data[0])
+ size = C.size_t(len(data))
} else {
- ptr = unsafe.Pointer(nil)
+ data = []byte{0}
+ size = C.size_t(0)
}
- ecode := C.git_blob_create_frombuffer(&id, repo.ptr, ptr, C.size_t(len(data)))
+ ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
if ecode < 0 {
return nil, MakeGitError(ecode)
}