From 4f3582910a5b48772a5235e26654f8d3568712d1 Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Thu, 17 Jul 2025 16:35:54 -0700 Subject: [PATCH] closefrom: Appease static analyzers sprintf paranoia While the math is correct on the buffer being adequate, some static analyzers like to complain rather than do the math. Appease them by using snprintf instead. Signed-off-by: Stewart Smith --- ccan/closefrom/closefrom.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ccan/closefrom/closefrom.c b/ccan/closefrom/closefrom.c index 177b05ee..e796ed29 100644 --- a/ccan/closefrom/closefrom.c +++ b/ccan/closefrom/closefrom.c @@ -80,7 +80,7 @@ static bool can_open_proc_pid_fd(void) char dnam[PROC_PID_FD_LEN]; DIR *dir; - sprintf(dnam, "/proc/%ld/fd", (long) getpid()); + snprintf(dnam, sizeof(dnam), "/proc/%ld/fd", (long) getpid()); dir = opendir(dnam); if (!dir) return false; @@ -159,7 +159,7 @@ void closefrom(int fromfd) maxfd = sysconf(_SC_OPEN_MAX); - sprintf(dnam, "/proc/%ld/fd", (long) getpid()); + snprintf(dnam, sizeof(dnam), "/proc/%ld/fd", (long) getpid()); dir = try_opendir(dnam, &fromfd, maxfd); if (!dir) dir = try_opendir("/dev/fd", &fromfd, maxfd);