Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions sqlx-sqlite/src/statement/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::os::raw::{c_char, c_int};
use std::ptr;
use std::ptr::NonNull;
use std::slice::from_raw_parts;
use std::str::{from_utf8, from_utf8_unchecked};
use std::str::from_utf8;
use std::sync::Arc;

#[derive(Debug)]
Expand Down Expand Up @@ -77,7 +77,8 @@ impl StatementHandle {
let raw = sqlite3_sql(self.0.as_ptr());
debug_assert!(!raw.is_null());

from_utf8_unchecked(CStr::from_ptr(raw).to_bytes())
from_utf8(CStr::from_ptr(raw).to_bytes())
.expect("sqlite3_sql() returned non-UTF-8 string")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turning these into panics is a step up from undefined behavior but long-term we might want to make this a recoverable error.

This is fine to merge as-is, I just wanted to get that on record.

}
}

Expand Down Expand Up @@ -107,7 +108,8 @@ impl StatementHandle {
let name = sqlite3_column_name(self.0.as_ptr(), check_col_idx!(index));
debug_assert!(!name.is_null());

from_utf8_unchecked(CStr::from_ptr(name).to_bytes())
from_utf8(CStr::from_ptr(name).to_bytes())
.expect("sqlite3_column_name() returned non-UTF-8 column name")
}
}

Expand Down Expand Up @@ -139,7 +141,10 @@ impl StatementHandle {
let db_name = sqlite3_column_database_name(self.0.as_ptr(), check_col_idx!(index));

if !db_name.is_null() {
Some(from_utf8_unchecked(CStr::from_ptr(db_name).to_bytes()))
Some(
from_utf8(CStr::from_ptr(db_name).to_bytes())
.expect("sqlite3_column_database_name() returned non-UTF-8 string"),
)
} else {
None
}
Expand All @@ -151,7 +156,10 @@ impl StatementHandle {
let table_name = sqlite3_column_table_name(self.0.as_ptr(), check_col_idx!(index));

if !table_name.is_null() {
Some(from_utf8_unchecked(CStr::from_ptr(table_name).to_bytes()))
Some(
from_utf8(CStr::from_ptr(table_name).to_bytes())
.expect("sqlite3_column_table_name() returned non-UTF-8 string"),
)
} else {
None
}
Expand All @@ -163,7 +171,10 @@ impl StatementHandle {
let origin_name = sqlite3_column_origin_name(self.0.as_ptr(), check_col_idx!(index));

if !origin_name.is_null() {
Some(from_utf8_unchecked(CStr::from_ptr(origin_name).to_bytes()))
Some(
from_utf8(CStr::from_ptr(origin_name).to_bytes())
.expect("sqlite3_column_origin_name() returned non-UTF-8 string"),
)
} else {
None
}
Expand Down Expand Up @@ -191,7 +202,8 @@ impl StatementHandle {
return None;
}

let decl = from_utf8_unchecked(CStr::from_ptr(decl).to_bytes());
let decl = from_utf8(CStr::from_ptr(decl).to_bytes())
.expect("sqlite3_column_decltype() returned non-UTF-8 string");
let ty: DataType = decl.parse().ok()?;

Some(SqliteTypeInfo(ty))
Expand Down Expand Up @@ -285,7 +297,10 @@ impl StatementHandle {
return None;
}

Some(from_utf8_unchecked(CStr::from_ptr(name).to_bytes()))
Some(
from_utf8(CStr::from_ptr(name).to_bytes())
.expect("sqlite3_bind_parameter_name() returned non-UTF-8 string"),
)
}
}

Expand Down
Loading