Use our own function to parse int
This commit is contained in:
parent
bbe4b69c8d
commit
d2cb638fcd
@ -120,7 +120,7 @@ static void main_daemon() {
|
||||
parse_prop_file("/system/build.prop", [](auto key, auto val) -> bool {
|
||||
if (key == "ro.build.version.sdk") {
|
||||
LOGI("* Device API level: %s\n", val.data());
|
||||
SDK_INT = atoi(val.data());
|
||||
SDK_INT = parse_int(val);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <magisk.h>
|
||||
#include <db.h>
|
||||
#include <daemon.h>
|
||||
#include <utils.h>
|
||||
|
||||
#define DB_VERSION 9
|
||||
|
||||
@ -42,7 +43,7 @@ int db_settings::getKeyIdx(string_view key) const {
|
||||
}
|
||||
|
||||
static int ver_cb(void *ver, int, char **data, char **) {
|
||||
*((int *) ver) = atoi(data[0]);
|
||||
*((int *) ver) = parse_int(data[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -199,7 +200,7 @@ char *db_exec(const char *sql, const db_row_cb &fn) {
|
||||
int get_db_settings(db_settings &cfg, int key) {
|
||||
char *err;
|
||||
auto settings_cb = [&](db_row &row) -> bool {
|
||||
cfg[row["key"]] = atoi(row["value"].data());
|
||||
cfg[row["key"]] = parse_int(row["value"]);
|
||||
LOGD("magiskdb: query %s=[%s]\n", row["key"].data(), row["value"].data());
|
||||
return true;
|
||||
};
|
||||
@ -237,9 +238,9 @@ int get_uid_policy(int uid, su_access &su) {
|
||||
sprintf(query, "SELECT policy, logging, notification FROM policies "
|
||||
"WHERE uid=%d AND (until=0 OR until>%li)", uid, time(nullptr));
|
||||
err = db_exec(query, [&](db_row &row) -> bool {
|
||||
su.policy = (policy_t) atoi(row["policy"].data());
|
||||
su.log = atoi(row["logging"].data());
|
||||
su.notify = atoi(row["notification"].data());
|
||||
su.policy = (policy_t) parse_int(row["policy"]);
|
||||
su.log = parse_int(row["logging"]);
|
||||
su.notify = parse_int(row["notification"]);
|
||||
LOGD("magiskdb: query policy=[%d] log=[%d] notify=[%d]\n", su.policy, su.log, su.notify);
|
||||
return true;
|
||||
});
|
||||
|
@ -38,21 +38,6 @@ void clean_magisk_props();
|
||||
void crawl_procfs(const std::function<bool (int)> &fn);
|
||||
bool proc_name_match(int pid, const char *name);
|
||||
|
||||
/*
|
||||
* Bionic's atoi runs through strtol().
|
||||
* Use our own implementation for faster conversion.
|
||||
*/
|
||||
static inline int parse_int(const char *s) {
|
||||
int val = 0;
|
||||
char c;
|
||||
while ((c = *(s++))) {
|
||||
if (c > '9' || c < '0')
|
||||
return -1;
|
||||
val = val * 10 + c - '0';
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
extern pthread_t proc_monitor_thread;
|
||||
extern bool hide_enabled;
|
||||
extern pthread_mutex_t monitor_lock;
|
||||
|
@ -177,7 +177,7 @@ int su_client_main(int argc, char *argv[]) {
|
||||
if (pw)
|
||||
su_req.uid = pw->pw_uid;
|
||||
else
|
||||
su_req.uid = atoi(argv[optind]);
|
||||
su_req.uid = parse_int(argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,7 @@ int strend(const char *s1, const char *s2);
|
||||
char *rtrim(char *str);
|
||||
void init_argv0(int argc, char **argv);
|
||||
void set_nice_name(const char *name);
|
||||
int parse_int(const char *s);
|
||||
|
||||
#define getline __getline
|
||||
#define getdelim __getdelim
|
||||
@ -203,6 +204,11 @@ void mmap_rw(const char *filename, B &buf, L &sz) {
|
||||
|
||||
// misc.cpp
|
||||
|
||||
template <class S>
|
||||
int parse_int(S __s) {
|
||||
return parse_int(__s.data());
|
||||
}
|
||||
|
||||
int new_daemon_thread(void *(*start_routine) (void *), void *arg = nullptr,
|
||||
const pthread_attr_t *attr = nullptr);
|
||||
|
||||
|
@ -230,3 +230,18 @@ char *rtrim(char *str) {
|
||||
str[len] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bionic's atoi runs through strtol().
|
||||
* Use our own implementation for faster conversion.
|
||||
*/
|
||||
int parse_int(const char *s) {
|
||||
int val = 0;
|
||||
char c;
|
||||
while ((c = *(s++))) {
|
||||
if (c > '9' || c < '0')
|
||||
return -1;
|
||||
val = val * 10 + c - '0';
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user