Segmentation fault on prepare_cached with an empty query

With an empty query is prepared, sqlite3 returns no error but a null pointer.
And then `sqlite3_sql` returns null.
Which make `CStr::from_ptr` crash.
This commit is contained in:
gwenn
2019-10-29 19:24:18 +01:00
parent 31139bbe9f
commit edfd7658c3
5 changed files with 41 additions and 7 deletions

View File

@@ -14,6 +14,10 @@ impl RawStatement {
RawStatement(stmt, tail)
}
pub fn is_null(&self) -> bool {
self.0.is_null()
}
pub unsafe fn ptr(&self) -> *mut ffi::sqlite3_stmt {
self.0
}
@@ -95,8 +99,12 @@ impl RawStatement {
unsafe { ffi::sqlite3_clear_bindings(self.0) }
}
pub fn sql(&self) -> &CStr {
unsafe { CStr::from_ptr(ffi::sqlite3_sql(self.0)) }
pub fn sql(&self) -> Option<&CStr> {
if self.0.is_null() {
None
} else {
Some(unsafe { CStr::from_ptr(ffi::sqlite3_sql(self.0)) })
}
}
pub fn finalize(mut self) -> c_int {