OSDN Git Service

Get rid of warnings when compiled with -Wformat-security
authorNick Kralevich <nnk@google.com>
Thu, 13 May 2010 23:24:26 +0000 (16:24 -0700)
committerNick Kralevich <nnk@google.com>
Fri, 14 May 2010 00:38:54 +0000 (17:38 -0700)
Change-Id: Ib0a56e508734b1eca8b6cf125fd07efefee854aa

power/power.c

index 8dea0a2..1dac44b 100644 (file)
@@ -149,7 +149,8 @@ set_last_user_activity_timeout(int64_t delay)
     if (fd >= 0) {
         char buf[32];
         ssize_t len;
-        len = sprintf(buf, "%d", ((int)(delay)));
+        len = snprintf(buf, sizeof(buf), "%d", ((int)(delay)));
+        buf[sizeof(buf) - 1] = '\0';
         len = write(fd, buf, len);
         close(fd);
         return 0;
@@ -175,9 +176,11 @@ set_screen_state(int on)
     char buf[32];
     int len;
     if(on)
-        len = sprintf(buf, on_state);
+        len = snprintf(buf, sizeof(buf), "%s", on_state);
     else
-        len = sprintf(buf, off_state);
+        len = snprintf(buf, sizeof(buf), "%s", off_state);
+
+    buf[sizeof(buf) - 1] = '\0';
     len = write(g_fds[REQUEST_STATE], buf, len);
     if(len < 0) {
         LOGE("Failed setting last user activity: g_error=%d\n", g_error);