diff options
author | Wei Wang <wvw@google.com> | 2016-10-12 14:35:51 -0700 |
---|---|---|
committer | Wei Wang <wvw@google.com> | 2016-10-12 20:50:42 -0700 |
commit | fc665a1e9af6b80dd3b1be6e23d8ba130de223ba (patch) | |
tree | 5cffcc08ca8ece6dc616a608c7c175d0b7797ce0 /ANRdaemon | |
parent | 5cd405316e1b98e00ad2cf02f930a5748982edcd (diff) | |
download | extras-fc665a1e9af6b80dd3b1be6e23d8ba130de223ba.tar.gz |
ANRdaemon: replace sprintf with snprintf
Test: run ANRdaemon
Change-Id: I1b39647c2ea0a54c90ec210ccb9a14430944e21d
Diffstat (limited to 'ANRdaemon')
-rw-r--r-- | ANRdaemon/ANRdaemon.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ANRdaemon/ANRdaemon.cpp b/ANRdaemon/ANRdaemon.cpp index 2419da32..c33414c6 100644 --- a/ANRdaemon/ANRdaemon.cpp +++ b/ANRdaemon/ANRdaemon.cpp @@ -134,7 +134,7 @@ static void get_cpu_stat(cpu_stat_t *cpu) { if ((fp = fopen("/proc/stat", "r")) == NULL) { err = true; - sprintf(err_msg, "can't read from /proc/stat with errno %d", errno); + snprintf(err_msg, sizeof(err_msg), "can't read from /proc/stat with errno %d", errno); } else { if (fscanf(fp, params, &cpu->utime, &cpu->ntime, &cpu->stime, &cpu->itime, &cpu->iowtime, &cpu->irqtime, @@ -193,7 +193,7 @@ static int dfs_enable(bool enable, const char* path) { int fd = open(path, O_WRONLY); if (fd == -1) { err = true; - sprintf(err_msg, "Can't open %s. Error: %d", path, errno); + snprintf(err_msg, sizeof(err_msg), "Can't open %s. Error: %d", path, errno); return -1; } const char* control = (enable?"1":"0"); @@ -206,7 +206,7 @@ static int dfs_enable(bool enable, const char* path) { } err = true; - sprintf(err_msg, "Error %d in writing to %s.", errno, path); + snprintf(err_msg, sizeof(err_msg), "Error %d in writing to %s.", errno, path); } close(fd); return (err?-1:0); @@ -217,16 +217,16 @@ static int dfs_enable(bool enable, const char* path) { */ static void dfs_set_property(uint64_t mtag, const char* mapp, bool enable) { char buf[64]; - snprintf(buf, 64, "%#" PRIx64, mtag); + snprintf(buf, sizeof(buf), "%#" PRIx64, mtag); if (property_set(dfs_tags_property, buf) < 0) { err = true; - sprintf(err_msg, "Failed to set debug tags system properties."); + snprintf(err_msg, sizeof(err_msg), "Failed to set debug tags system properties."); } if (strlen(mapp) > 0 && property_set(dfs_apps_property, mapp) < 0) { err = true; - sprintf(err_msg, "Failed to set debug applications."); + snprintf(err_msg, sizeof(err_msg), "Failed to set debug applications."); } if (log_sched) { @@ -404,13 +404,13 @@ static int set_tracing_buffer_size(void) { int fd = open(dfs_buffer_size_path, O_WRONLY); if (fd == -1) { err = true; - sprintf(err_msg, "Can't open atrace buffer size file under /d/tracing."); + snprintf(err_msg, sizeof(err_msg), "Can't open atrace buffer size file under /d/tracing."); return -1; } ssize_t len = strlen(buf_size_kb); if (write(fd, buf_size_kb, len) != len) { err = true; - sprintf(err_msg, "Error in writing to atrace buffer size file."); + snprintf(err_msg, sizeof(err_msg), "Error in writing to atrace buffer size file."); } close(fd); return (err?-1:0); |