aboutsummaryrefslogtreecommitdiff
path: root/sqlite3.go
diff options
context:
space:
mode:
authorEvgeniy Makeev <evgeniym@fb.com>2017-06-20 17:36:44 -0700
committerEvgeniy Makeev <evgeniym@fb.com>2017-06-20 17:36:44 -0700
commitef9f773b24d2ec1611476e580c032e98068e481a (patch)
tree31af7258126a45568ec60e5ee40fe8046fd85431 /sqlite3.go
parentMerge pull request #427 from otoolep/conn_stmt_race (diff)
downloadgolite-ef9f773b24d2ec1611476e580c032e98068e481a.tar.gz
golite-ef9f773b24d2ec1611476e580c032e98068e481a.tar.xz
Fix for cgo panic, issue #428: https://github.com/mattn/go-sqlite3/issues/428
Diffstat (limited to 'sqlite3.go')
-rw-r--r--sqlite3.go11
1 files changed, 4 insertions, 7 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 0cd4666..b34c3a5 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -747,7 +747,7 @@ type bindArg struct {
v driver.Value
}
-var placeHolder byte = 0
+var placeHolder = []byte{0}
func (s *SQLiteStmt) bind(args []namedValue) error {
rv := C.sqlite3_reset(s.s)
@@ -770,7 +770,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
rv = C.sqlite3_bind_null(s.s, n)
case string:
if len(v) == 0 {
- rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder)), C.int(0))
+ rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.int(0))
} else {
b := []byte(v)
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 {
case float64:
rv = C.sqlite3_bind_double(s.s, n, C.double(v))
case []byte:
- var ptr *byte
if len(v) == 0 {
- ptr = &placeHolder
- } else {
- ptr = &v[0]
+ v = placeHolder
}
- rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(ptr), C.int(len(v)))
+ rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v)))
case time.Time:
b := []byte(v.Format(SQLiteTimestampFormats[0]))
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))