[OpenWrt-Devel] [PATCH] procd: Fix compile error with GCC8
Rosen Penev
rosenp at gmail.com
Thu Jun 21 16:58:54 EDT 2018
error: ‘%d’ directive output may be truncated writing between 2 and 10
bytes into a region of size 3 [-Werror=format-truncation=]
snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
^~~
note: directive argument in the range [0, 2147483647]
snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
^~~~~
note: ‘snprintf’ output between 3 and 11 bytes into a destination of size
3
snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
watchdog.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/watchdog.c b/watchdog.c
index ec10ba6..efe30f1 100644
--- a/watchdog.c
+++ b/watchdog.c
@@ -144,8 +144,9 @@ char* watchdog_fd(void)
{
static char fd_buf[3];
- if (wdt_fd < 0)
+ if (wdt_fd < 0 || wdt_fd > 99)
return NULL;
+
snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
return fd_buf;
--
2.17.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list