Merge "Cleanup uses of sprintf so we can deprecate it."
am: 2c5b89a64a
* commit '2c5b89a64a6ba2e62299635b8d81a17b59703b4c':
Cleanup uses of sprintf so we can deprecate it.
This commit is contained in:
commit
3368bdebba
9 changed files with 35 additions and 30 deletions
|
|
@ -600,7 +600,7 @@ int fs_mgr_mount_all(struct fstab *fstab)
|
||||||
fstab->recs[top_idx].fs_type);
|
fstab->recs[top_idx].fs_type);
|
||||||
if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) &&
|
if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) &&
|
||||||
strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) {
|
strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) {
|
||||||
int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY, 0644);
|
int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
INFO("%s(): also wipe %s\n", __func__, fstab->recs[top_idx].key_loc);
|
INFO("%s(): also wipe %s\n", __func__, fstab->recs[top_idx].key_loc);
|
||||||
wipe_block_device(fd, get_file_size(fd));
|
wipe_block_device(fd, get_file_size(fd));
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point)
|
||||||
uint64_t dev_sz;
|
uint64_t dev_sz;
|
||||||
int fd, rc = 0;
|
int fd, rc = 0;
|
||||||
|
|
||||||
if ((fd = open(fs_blkdev, O_WRONLY, 0644)) < 0) {
|
if ((fd = open(fs_blkdev, O_WRONLY)) < 0) {
|
||||||
ERROR("Cannot open block device. %s\n", strerror(errno));
|
ERROR("Cannot open block device. %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ public:
|
||||||
|
|
||||||
void store_sid(uint32_t uid, uint64_t sid) {
|
void store_sid(uint32_t uid, uint64_t sid) {
|
||||||
char filename[21];
|
char filename[21];
|
||||||
sprintf(filename, "%u", uid);
|
snprintf(filename, sizeof(filename), "%u", uid);
|
||||||
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
|
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
ALOGE("could not open file: %s: %s", filename, strerror(errno));
|
ALOGE("could not open file: %s: %s", filename, strerror(errno));
|
||||||
|
|
@ -102,7 +102,7 @@ public:
|
||||||
|
|
||||||
void maybe_store_sid(uint32_t uid, uint64_t sid) {
|
void maybe_store_sid(uint32_t uid, uint64_t sid) {
|
||||||
char filename[21];
|
char filename[21];
|
||||||
sprintf(filename, "%u", uid);
|
snprintf(filename, sizeof(filename), "%u", uid);
|
||||||
if (access(filename, F_OK) == -1) {
|
if (access(filename, F_OK) == -1) {
|
||||||
store_sid(uid, sid);
|
store_sid(uid, sid);
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ public:
|
||||||
uint64_t read_sid(uint32_t uid) {
|
uint64_t read_sid(uint32_t uid) {
|
||||||
char filename[21];
|
char filename[21];
|
||||||
uint64_t sid;
|
uint64_t sid;
|
||||||
sprintf(filename, "%u", uid);
|
snprintf(filename, sizeof(filename), "%u", uid);
|
||||||
int fd = open(filename, O_RDONLY);
|
int fd = open(filename, O_RDONLY);
|
||||||
if (fd < 0) return 0;
|
if (fd < 0) return 0;
|
||||||
read(fd, &sid, sizeof(sid));
|
read(fd, &sid, sizeof(sid));
|
||||||
|
|
@ -121,7 +121,7 @@ public:
|
||||||
|
|
||||||
void clear_sid(uint32_t uid) {
|
void clear_sid(uint32_t uid) {
|
||||||
char filename[21];
|
char filename[21];
|
||||||
sprintf(filename, "%u", uid);
|
snprintf(filename, sizeof(filename), "%u", uid);
|
||||||
if (remove(filename) < 0) {
|
if (remove(filename) < 0) {
|
||||||
ALOGE("%s: could not remove file [%s], attempting 0 write", __func__, strerror(errno));
|
ALOGE("%s: could not remove file [%s], attempting 0 write", __func__, strerror(errno));
|
||||||
store_sid(uid, 0);
|
store_sid(uid, 0);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ void parse_error(struct parse_state *state, const char *fmt, ...)
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int off;
|
int off;
|
||||||
|
|
||||||
snprintf(buf, 128, "%s: %d: ", state->filename, state->line);
|
snprintf(buf, sizeof(buf), "%s: %d: ", state->filename, state->line);
|
||||||
buf[127] = 0;
|
buf[127] = 0;
|
||||||
off = strlen(buf);
|
off = strlen(buf);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused)))
|
||||||
|
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
unsigned val = i + j * 3 + 1;
|
unsigned val = i + j * 3 + 1;
|
||||||
sprintf(str, "test_fence%d-%d", i, j);
|
snprintf(str, sizeof(str), "test_fence%d-%d", i, j);
|
||||||
int fd = sw_sync_fence_create(sync_timeline_fd, str, val);
|
int fd = sw_sync_fence_create(sync_timeline_fd, str, val);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
printf("can't create sync pt %d: %s", val, strerror(errno));
|
printf("can't create sync pt %d: %s", val, strerror(errno));
|
||||||
|
|
@ -106,7 +106,7 @@ int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused)))
|
||||||
|
|
||||||
sync_data[3].thread_no = 3;
|
sync_data[3].thread_no = 3;
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
sprintf(str, "merged_fence%d", j);
|
snprintf(str, sizeof(str), "merged_fence%d", j);
|
||||||
sync_data[3].fd[j] = sync_merge(str, sync_data[0].fd[j], sync_data[1].fd[j]);
|
sync_data[3].fd[j] = sync_merge(str, sync_data[0].fd[j], sync_data[1].fd[j]);
|
||||||
if (sync_data[3].fd[j] < 0) {
|
if (sync_data[3].fd[j] < 0) {
|
||||||
printf("can't merge sync pts %d and %d: %s\n",
|
printf("can't merge sync pts %d and %d: %s\n",
|
||||||
|
|
|
||||||
|
|
@ -190,17 +190,22 @@ public:
|
||||||
{
|
{
|
||||||
Mutex::Autolock _l(mMutex);
|
Mutex::Autolock _l(mMutex);
|
||||||
char buf[128];
|
char buf[128];
|
||||||
sprintf(buf, "Strong references on RefBase %p (weakref_type %p):\n", mBase, this);
|
snprintf(buf, sizeof(buf),
|
||||||
|
"Strong references on RefBase %p (weakref_type %p):\n",
|
||||||
|
mBase, this);
|
||||||
text.append(buf);
|
text.append(buf);
|
||||||
printRefsLocked(&text, mStrongRefs);
|
printRefsLocked(&text, mStrongRefs);
|
||||||
sprintf(buf, "Weak references on RefBase %p (weakref_type %p):\n", mBase, this);
|
snprintf(buf, sizeof(buf),
|
||||||
|
"Weak references on RefBase %p (weakref_type %p):\n",
|
||||||
|
mBase, this);
|
||||||
text.append(buf);
|
text.append(buf);
|
||||||
printRefsLocked(&text, mWeakRefs);
|
printRefsLocked(&text, mWeakRefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char name[100];
|
char name[100];
|
||||||
snprintf(name, 100, DEBUG_REFS_CALLSTACK_PATH "/%p.stack", this);
|
snprintf(name, sizeof(name), DEBUG_REFS_CALLSTACK_PATH "/%p.stack",
|
||||||
|
this);
|
||||||
int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 644);
|
int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 644);
|
||||||
if (rc >= 0) {
|
if (rc >= 0) {
|
||||||
write(rc, text.string(), text.length());
|
write(rc, text.string(), text.length());
|
||||||
|
|
@ -293,8 +298,8 @@ private:
|
||||||
char buf[128];
|
char buf[128];
|
||||||
while (refs) {
|
while (refs) {
|
||||||
char inc = refs->ref >= 0 ? '+' : '-';
|
char inc = refs->ref >= 0 ? '+' : '-';
|
||||||
sprintf(buf, "\t%c ID %p (ref %d):\n",
|
snprintf(buf, sizeof(buf), "\t%c ID %p (ref %d):\n",
|
||||||
inc, refs->id, refs->ref);
|
inc, refs->id, refs->ref);
|
||||||
out->append(buf);
|
out->append(buf);
|
||||||
#if DEBUG_REFS_CALLSTACK_ENABLED
|
#if DEBUG_REFS_CALLSTACK_ENABLED
|
||||||
out->append(refs->stack.toString("\t\t"));
|
out->append(refs->stack.toString("\t\t"));
|
||||||
|
|
|
||||||
|
|
@ -695,7 +695,7 @@ int newfs_msdos_main(int argc, char *argv[])
|
||||||
(u_int)tm->tm_min));
|
(u_int)tm->tm_min));
|
||||||
mk4(bsx->volid, x);
|
mk4(bsx->volid, x);
|
||||||
mklabel(bsx->label, opt_L ? opt_L : "NO NAME");
|
mklabel(bsx->label, opt_L ? opt_L : "NO NAME");
|
||||||
sprintf(buf, "FAT%u", fat);
|
snprintf(buf, sizeof(buf), "FAT%u", fat);
|
||||||
setstr(bsx->type, buf, sizeof(bsx->type));
|
setstr(bsx->type, buf, sizeof(bsx->type));
|
||||||
if (!opt_B) {
|
if (!opt_B) {
|
||||||
x1 += sizeof(struct bsx);
|
x1 += sizeof(struct bsx);
|
||||||
|
|
|
||||||
14
toolbox/ps.c
14
toolbox/ps.c
|
|
@ -57,16 +57,16 @@ static int ps_line(int pid, int tid)
|
||||||
int prio, nice, rtprio, sched, psr;
|
int prio, nice, rtprio, sched, psr;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
sprintf(statline, "/proc/%d", tid ? tid : pid);
|
snprintf(statline, sizeof(statline), "/proc/%d", tid ? tid : pid);
|
||||||
stat(statline, &stats);
|
stat(statline, &stats);
|
||||||
|
|
||||||
if(tid) {
|
if(tid) {
|
||||||
sprintf(statline, "/proc/%d/task/%d/stat", pid, tid);
|
snprintf(statline, sizeof(statline), "/proc/%d/task/%d/stat", pid, tid);
|
||||||
cmdline[0] = 0;
|
cmdline[0] = 0;
|
||||||
snprintf(macline, sizeof(macline), "/proc/%d/task/%d/attr/current", pid, tid);
|
snprintf(macline, sizeof(macline), "/proc/%d/task/%d/attr/current", pid, tid);
|
||||||
} else {
|
} else {
|
||||||
sprintf(statline, "/proc/%d/stat", pid);
|
snprintf(statline, sizeof(statline), "/proc/%d/stat", pid);
|
||||||
sprintf(cmdline, "/proc/%d/cmdline", pid);
|
snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
|
||||||
snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid);
|
snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid);
|
||||||
int fd = open(cmdline, O_RDONLY);
|
int fd = open(cmdline, O_RDONLY);
|
||||||
if(fd == 0) {
|
if(fd == 0) {
|
||||||
|
|
@ -149,7 +149,7 @@ static int ps_line(int pid, int tid)
|
||||||
|
|
||||||
pw = getpwuid(stats.st_uid);
|
pw = getpwuid(stats.st_uid);
|
||||||
if(pw == 0 || (display_flags & SHOW_NUMERIC_UID)) {
|
if(pw == 0 || (display_flags & SHOW_NUMERIC_UID)) {
|
||||||
sprintf(user,"%d",(int)stats.st_uid);
|
snprintf(user,sizeof(user),"%d",(int)stats.st_uid);
|
||||||
} else {
|
} else {
|
||||||
strcpy(user,pw->pw_name);
|
strcpy(user,pw->pw_name);
|
||||||
}
|
}
|
||||||
|
|
@ -208,7 +208,7 @@ static void print_exe_abi(int pid)
|
||||||
int fd, r;
|
int fd, r;
|
||||||
char exeline[1024];
|
char exeline[1024];
|
||||||
|
|
||||||
sprintf(exeline, "/proc/%d/exe", pid);
|
snprintf(exeline, sizeof(exeline), "/proc/%d/exe", pid);
|
||||||
fd = open(exeline, O_RDONLY);
|
fd = open(exeline, O_RDONLY);
|
||||||
if(fd == 0) {
|
if(fd == 0) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
|
@ -243,7 +243,7 @@ void ps_threads(int pid)
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
|
|
||||||
sprintf(tmp,"/proc/%d/task",pid);
|
snprintf(tmp,sizeof(tmp),"/proc/%d/task",pid);
|
||||||
d = opendir(tmp);
|
d = opendir(tmp);
|
||||||
if(d == 0) return;
|
if(d == 0) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,29 +258,29 @@ static void read_procs(void) {
|
||||||
|
|
||||||
proc->pid = proc->tid = pid;
|
proc->pid = proc->tid = pid;
|
||||||
|
|
||||||
sprintf(filename, "/proc/%d/stat", pid);
|
snprintf(filename, sizeof(filename), "/proc/%d/stat", pid);
|
||||||
read_stat(filename, proc);
|
read_stat(filename, proc);
|
||||||
|
|
||||||
sprintf(filename, "/proc/%d/cmdline", pid);
|
snprintf(filename, sizeof(filename), "/proc/%d/cmdline", pid);
|
||||||
read_cmdline(filename, proc);
|
read_cmdline(filename, proc);
|
||||||
|
|
||||||
sprintf(filename, "/proc/%d/status", pid);
|
snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
|
||||||
read_status(filename, proc);
|
read_status(filename, proc);
|
||||||
|
|
||||||
read_policy(pid, proc);
|
read_policy(pid, proc);
|
||||||
|
|
||||||
proc->num_threads = 0;
|
proc->num_threads = 0;
|
||||||
} else {
|
} else {
|
||||||
sprintf(filename, "/proc/%d/cmdline", pid);
|
snprintf(filename, sizeof(filename), "/proc/%d/cmdline", pid);
|
||||||
read_cmdline(filename, &cur_proc);
|
read_cmdline(filename, &cur_proc);
|
||||||
|
|
||||||
sprintf(filename, "/proc/%d/status", pid);
|
snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
|
||||||
read_status(filename, &cur_proc);
|
read_status(filename, &cur_proc);
|
||||||
|
|
||||||
proc = NULL;
|
proc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(filename, "/proc/%d/task", pid);
|
snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
|
||||||
task_dir = opendir(filename);
|
task_dir = opendir(filename);
|
||||||
if (!task_dir) continue;
|
if (!task_dir) continue;
|
||||||
|
|
||||||
|
|
@ -295,7 +295,7 @@ static void read_procs(void) {
|
||||||
|
|
||||||
proc->pid = pid; proc->tid = tid;
|
proc->pid = pid; proc->tid = tid;
|
||||||
|
|
||||||
sprintf(filename, "/proc/%d/task/%d/stat", pid, tid);
|
snprintf(filename, sizeof(filename), "/proc/%d/task/%d/stat", pid, tid);
|
||||||
read_stat(filename, proc);
|
read_stat(filename, proc);
|
||||||
|
|
||||||
read_policy(tid, proc);
|
read_policy(tid, proc);
|
||||||
|
|
@ -484,7 +484,7 @@ static void print_procs(void) {
|
||||||
if (user && user->pw_name) {
|
if (user && user->pw_name) {
|
||||||
user_str = user->pw_name;
|
user_str = user->pw_name;
|
||||||
} else {
|
} else {
|
||||||
snprintf(user_buf, 20, "%d", proc->uid);
|
snprintf(user_buf, sizeof(user_buf), "%d", proc->uid);
|
||||||
user_str = user_buf;
|
user_str = user_buf;
|
||||||
}
|
}
|
||||||
if (!threads) {
|
if (!threads) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue