From 2a3554747a0fc7aaca82988657c0a278d84eecce Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Wed, 1 Mar 2023 18:28:40 +0200 Subject: [PATCH] onewire_parser.c: Fix compiler warnings about string lengths Compilers are picky about not truncating the output when copying data with strncpy. From the static buffer sizes it sees the potential buffer truncation, so adjust the buffer sizes so that it is not possible to truncate buffers and leave the data unterminated. Signed-off-by: Timo Kokkonen --- onewire_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onewire_parser.c b/onewire_parser.c index 07d359b..958cff9 100644 --- a/onewire_parser.c +++ b/onewire_parser.c @@ -107,7 +107,7 @@ static int parse_opts(const char *str, char *ow_path, size_t pathlen, break; /* Copy the onewire path without options */ - strncpy(ow_path, start_str, pathlen); + strncpy(ow_path, start_str, pathlen - 1); ow_path[str - start_str] = '\0'; /* Get the next non-space, which is where the argument begins */ @@ -130,7 +130,7 @@ static int parse_opts(const char *str, char *ow_path, size_t pathlen, static int make_uncached(char *path, size_t len) { int ret; - char p1[1024], p2[1024], *p = path; + char p1[1028], p2[1028], *p = path; if (strstr(path, "/uncached/")) return 0; -- 2.45.0