From a0c87633883d8a6eb4374cbbb8d55e60315314ff Mon Sep 17 00:00:00 2001 From: simon987 Date: Fri, 27 Dec 2019 16:04:59 -0500 Subject: [PATCH] bugfix --- fastimagehash.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fastimagehash.go b/fastimagehash.go index 7fbdcd1..cc40340 100644 --- a/fastimagehash.go +++ b/fastimagehash.go @@ -155,7 +155,13 @@ func PHashFile(filepath string, hashSize, highFreqFactor int) (*Hash, Code) { func PHashMem(buf []byte, hashSize, highFreqFactor int) (*Hash, Code) { var ret C.int - hash := C.phash_mem_wr(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), C.int(hashSize), C.int(highFreqFactor), &ret) + + p := C.malloc(C.size_t(len(buf))) + cBuf := (*[1 << 30]byte)(p) + copy(cBuf[:], buf) + + hash := C.phash_mem_wr(p, C.size_t(len(buf)), C.int(hashSize), C.int(highFreqFactor), &ret) + C.free(p) return retHash(hash, hashSize, ret) }