]> git.itanic.dy.fi Git - rrdd/commitdiff
onewire_parser.c: Fix compiler warnings about string lengths master
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 1 Mar 2023 16:28:40 +0000 (18:28 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 1 Mar 2023 16:28:40 +0000 (18:28 +0200)
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 <timo.t.kokkonen@iki.fi>
onewire_parser.c

index 07d359b7c8dadf2c43035600816b2c0b5e1d1fd3..958cff952cb7c8bbdfcca76f0f013ed0f6e92bd3 100644 (file)
@@ -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;