1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: disallow struct int to ptr outside unsafe (#17923)

This commit is contained in:
Swastik Baranwal
2023-04-13 11:08:21 +05:30
committed by GitHub
parent 92cb7468ce
commit 3d99f1f2c2
36 changed files with 124 additions and 47 deletions

View File

@ -126,7 +126,7 @@ fn C.sqlite3_changes(&C.sqlite3) int
// connect Opens the connection with a database.
pub fn connect(path string) !DB {
db := &C.sqlite3(0)
db := &C.sqlite3(unsafe { nil })
code := C.sqlite3_open(&char(path.str), &db)
if code != 0 {
return &SQLError{
@ -181,7 +181,7 @@ pub fn (db &DB) get_affected_rows_count() int {
// Returns a single cell with value int.
pub fn (db &DB) q_int(query string) int {
stmt := &C.sqlite3_stmt(0)
stmt := &C.sqlite3_stmt(unsafe { nil })
defer {
C.sqlite3_finalize(stmt)
}
@ -194,7 +194,7 @@ pub fn (db &DB) q_int(query string) int {
// Returns a single cell with value string.
pub fn (db &DB) q_string(query string) string {
stmt := &C.sqlite3_stmt(0)
stmt := &C.sqlite3_stmt(unsafe { nil })
defer {
C.sqlite3_finalize(stmt)
}
@ -209,7 +209,7 @@ pub fn (db &DB) q_string(query string) string {
// Result codes: https://www.sqlite.org/rescode.html
[manualfree]
pub fn (db &DB) exec(query string) ([]Row, int) {
stmt := &C.sqlite3_stmt(0)
stmt := &C.sqlite3_stmt(unsafe { nil })
defer {
C.sqlite3_finalize(stmt)
}
@ -276,7 +276,7 @@ pub fn (db &DB) error_message(code int, query string) IError {
// In case you don't expect any row results, but still want a result code.
// e.g. INSERT INTO ... VALUES (...)
pub fn (db &DB) exec_none(query string) int {
stmt := &C.sqlite3_stmt(0)
stmt := &C.sqlite3_stmt(unsafe { nil })
C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
code := C.sqlite3_step(stmt)
C.sqlite3_finalize(stmt)

View File

@ -149,7 +149,7 @@ pub enum OpenModeFlag {
// connect_full Opens connection to sqlite database. It gives more control than `open`.
// Flags give control over readonly and create decisions. Specific VFS can be chosen.
pub fn connect_full(path string, mode_flags []OpenModeFlag, vfs_name string) !DB {
db := &C.sqlite3(0)
db := &C.sqlite3(unsafe { nil })
mut flags := 0