Don't use a manually-sized buffer for the PID.
Change-Id: Ibdda590b828c61caa488e959f3e596dc981a2c65
diff --git a/server/NetdConstants.h b/server/NetdConstants.h
index 5c3fde0..686e974 100644
--- a/server/NetdConstants.h
+++ b/server/NetdConstants.h
@@ -44,6 +44,7 @@
#define __INT_STRLEN(i) sizeof(#i)
#define _INT_STRLEN(i) __INT_STRLEN(i)
+#define INT32_STRLEN _INT_STRLEN(INT32_MIN)
#define UINT32_STRLEN _INT_STRLEN(UINT32_MAX)
#define UINT32_HEX_STRLEN sizeof("0x12345678")
diff --git a/server/main.cpp b/server/main.cpp
index 9e84c1c..cf3d5ec 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -126,8 +126,8 @@
}
static bool write_pid_file() {
- char pid_buf[20]; // current pid_max is 32768, so plenty of room
- snprintf(pid_buf, sizeof(pid_buf), "%ld\n", (long)getpid());
+ char pid_buf[INT32_STRLEN];
+ snprintf(pid_buf, sizeof(pid_buf), "%d\n", (int) getpid());
int fd = open(PID_FILE_PATH, PID_FILE_FLAGS, PID_FILE_MODE);
if (fd == -1) {