fix warning: ‘strndup’ specified bound 4096 exceeds source size 2 [-Wstringop-overread]

In function ‘allocate_paths’,
    inlined from ‘xfer_options_parse_args’ at xfer-options.c:388:8:
xfer-options.c:69:34: warning: ‘strndup’ specified bound 4096 exceeds source size 2 [-Wstringop-overread]
   69 |                 xfer->paths[0] = strndup("-", PATH_MAX);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
ck 2023-06-18 17:46:23 +02:00 committed by GitHub
parent b399fb85a9
commit 041c190799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,12 +66,12 @@ static int allocate_paths(struct xfer_context *xfer, char *const *paths,
xfer->path_count = count; xfer->path_count = count;
if (stdio) { if (stdio) {
xfer->paths[0] = strndup("-", PATH_MAX); xfer->paths[0] = strndup("-", strlen("-"));
if (xfer->paths[0] == NULL) if (xfer->paths[0] == NULL)
return -ENOMEM; return -ENOMEM;
} else { } else {
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
xfer->paths[i] = strndup(paths[i], PATH_MAX); xfer->paths[i] = strndup(paths[i], strlen(paths[i]));
if (xfer->paths[i] == NULL) if (xfer->paths[i] == NULL)
return -ENOMEM; return -ENOMEM;
} }