Skip to content

Commit ef9f773

Browse files
committed
Fix for cgo panic, issue #428: #428
1 parent a819994 commit ef9f773

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

sqlite3.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ type bindArg struct {
747747
v driver.Value
748748
}
749749

750-
var placeHolder byte = 0
750+
var placeHolder = []byte{0}
751751

752752
func (s *SQLiteStmt) bind(args []namedValue) error {
753753
rv := C.sqlite3_reset(s.s)
@@ -770,7 +770,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
770770
rv = C.sqlite3_bind_null(s.s, n)
771771
case string:
772772
if len(v) == 0 {
773-
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder)), C.int(0))
773+
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.int(0))
774774
} else {
775775
b := []byte(v)
776776
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
@@ -786,13 +786,10 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
786786
case float64:
787787
rv = C.sqlite3_bind_double(s.s, n, C.double(v))
788788
case []byte:
789-
var ptr *byte
790789
if len(v) == 0 {
791-
ptr = &placeHolder
792-
} else {
793-
ptr = &v[0]
790+
v = placeHolder
794791
}
795-
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(ptr), C.int(len(v)))
792+
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v)))
796793
case time.Time:
797794
b := []byte(v.Format(SQLiteTimestampFormats[0]))
798795
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))

0 commit comments

Comments
 (0)