dumpstate: convert sprintfs to snprintfs

Bug: 28731007
Change-Id: Icfa4d6dfaf69e989ec785146a6bde1afb6a6f345
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index f1a1ed6..09c2e7f 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -188,7 +188,7 @@
     char taskpath[255];
     for_each_tid_func *func = (for_each_tid_func *) arg;
 
-    sprintf(taskpath, "/proc/%d/task", pid);
+    snprintf(taskpath, sizeof(taskpath), "/proc/%d/task", pid);
 
     if (!(d = opendir(taskpath))) {
         printf("Failed to open %s (%s)\n", taskpath, strerror(errno));
@@ -210,7 +210,7 @@
         if (tid == pid)
             continue;
 
-        sprintf(commpath,"/proc/%d/comm", tid);
+        snprintf(commpath, sizeof(commpath), "/proc/%d/comm", tid);
         memset(comm, 0, sizeof(comm));
         if ((fd = TEMP_FAILURE_RETRY(open(commpath, O_RDONLY | O_CLOEXEC))) < 0) {
             strcpy(comm, "N/A");
@@ -244,7 +244,7 @@
 
     memset(buffer, 0, sizeof(buffer));
 
-    sprintf(path, "/proc/%d/wchan", tid);
+    snprintf(path, sizeof(path), "/proc/%d/wchan", tid);
     if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) {
         printf("Failed to open '%s' (%s)\n", path, strerror(errno));
         return;
@@ -309,7 +309,7 @@
 
     memset(buffer, 0, sizeof(buffer));
 
-    sprintf(path, "/proc/%d/stat", pid);
+    snprintf(path, sizeof(path), "/proc/%d/stat", pid);
     if ((fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))) < 0) {
         printf("Failed to open '%s' (%s)\n", path, strerror(errno));
         return;
@@ -397,8 +397,8 @@
     char title[255];
     char arg[255];
 
-    sprintf(title, "SHOW MAP %d (%s)", pid, name);
-    sprintf(arg, "%d", pid);
+    snprintf(title, sizeof(title), "SHOW MAP %d (%s)", pid, name);
+    snprintf(arg, sizeof(arg), "%d", pid);
     run_command(title, 10, SU_PATH, "root", "showmap", "-q", arg, NULL);
 }
 
@@ -1191,8 +1191,8 @@
         int new_total = weight_total * 1.2;
         MYLOGD("Adjusting total weight from %d to %d\n", weight_total, new_total);
         weight_total = new_total;
-        sprintf(key, "dumpstate.%d.max", getpid());
-        sprintf(value, "%d", weight_total);
+        snprintf(key, sizeof(key), "dumpstate.%d.max", getpid());
+        snprintf(value, sizeof(value), "%d", weight_total);
         int status = property_set(key, value);
         if (status) {
             MYLOGE("Could not update max weight by setting system property %s to %s: %d\n",
@@ -1200,8 +1200,8 @@
         }
     }
 
-    sprintf(key, "dumpstate.%d.progress", getpid());
-    sprintf(value, "%d", progress);
+    snprintf(key, sizeof(key), "dumpstate.%d.progress", getpid());
+    snprintf(value, sizeof(value), "%d", progress);
 
     if (progress % 100 == 0) {
         // We don't want to spam logcat, so only log multiples of 100.