diff options
author | Thomas Leske <thomas@leske.biz> | 2012-08-20 17:20:58 +0200 |
---|---|---|
committer | Thomas Leske <thomas@leske.biz> | 2012-08-20 17:20:58 +0200 |
commit | a4e5e7a617347421764703979ebf8b78320ad3e4 (patch) | |
tree | c72ceaaa6303472c71b4fae25907abd7868de658 /sqlite3.go | |
parent | Merge pull request #18 from coolaj86/patch-1 (diff) | |
download | golite-a4e5e7a617347421764703979ebf8b78320ad3e4.tar.gz golite-a4e5e7a617347421764703979ebf8b78320ad3e4.tar.xz |
bug fix: Byte slices belong to the caller and so must be copies.
With the exeption of slices in the result type sql.RawBytes,
new calls to Sqlite must not corrupt slices.
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -297,7 +297,14 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { case C.SQLITE_BLOB: n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i))) p := C.sqlite3_column_blob(rc.s.s, C.int(i)) - dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n] + switch dest[i].(type) { + case sql.RawBytes: + dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n] + default: + slice := make([]byte, n) + copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]) + dest[i] = slice + } case C.SQLITE_NULL: dest[i] = nil case C.SQLITE_TEXT: |