refactor(sqlite): replace sscanf with parse

This commit is contained in:
dignifiedquire
2019-05-29 00:06:52 +02:00
parent a53f7c0fca
commit b296ccf5a5
3 changed files with 16 additions and 22 deletions

View File

@@ -1299,23 +1299,19 @@ pub unsafe fn dc_sqlite3_set_config_int64(
ret ret
} }
pub unsafe fn dc_sqlite3_get_config_int64( pub fn dc_sqlite3_get_config_int64(
context: &Context, context: &Context,
sql: &dc_sqlite3_t, sql: &dc_sqlite3_t,
key: *const libc::c_char, key: *const libc::c_char,
def: int64_t, def: i64,
) -> int64_t { ) -> i64 {
let str = dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char); let s = unsafe { dc_sqlite3_get_config(context, sql, key, 0 as *const libc::c_char) };
if str.is_null() { if s.is_null() {
return def; return def;
} }
let mut ret = 0 as int64_t;
sscanf( let ret: i64 = to_str(s).parse().unwrap_or_default();
str, unsafe { free(s as *mut libc::c_void) };
b"%lld\x00" as *const u8 as *const libc::c_char,
&mut ret as *mut int64_t,
);
free(str as *mut libc::c_void);
ret ret
} }

View File

@@ -334,14 +334,12 @@ fn set_config_int64(context: &Context, key: &str, value: i64) {
} }
fn is_expired(context: &Context) -> bool { fn is_expired(context: &Context) -> bool {
let expire_timestamp = unsafe { let expire_timestamp = dc_sqlite3_get_config_int64(
dc_sqlite3_get_config_int64( context,
context, &context.sql.clone().read().unwrap(),
&context.sql.clone().read().unwrap(), b"oauth2_timestamp_expires\x00" as *const u8 as *const libc::c_char,
b"oauth2_timestamp_expires\x00" as *const u8 as *const libc::c_char, 0i32 as int64_t,
0i32 as int64_t, );
)
} as i64;
if expire_timestamp <= 0 { if expire_timestamp <= 0 {
return false; return false;

View File

@@ -4,8 +4,8 @@ use crate::types::*;
pub use libc::{ pub use libc::{
atoi, calloc, close, closedir, exit, fclose, fgets, fopen, fread, free, fseek, ftell, fwrite, atoi, calloc, close, closedir, exit, fclose, fgets, fopen, fread, free, fseek, ftell, fwrite,
malloc, memcmp, memcpy, memmove, memset, mkdir, open, opendir, printf, read, readdir, realloc, malloc, memcmp, memcpy, memmove, memset, mkdir, open, opendir, printf, read, readdir, realloc,
remove, sprintf, sscanf, strcat, strchr, strcmp, strcpy, strcspn, strlen, strncmp, strncpy, remove, sprintf, strcat, strchr, strcmp, strcpy, strcspn, strlen, strncmp, strncpy, strrchr,
strrchr, strspn, strstr, strtol, system, tolower, write, strspn, strstr, strtol, system, tolower, write,
}; };
pub unsafe fn strdup(s: *const libc::c_char) -> *mut libc::c_char { pub unsafe fn strdup(s: *const libc::c_char) -> *mut libc::c_char {