[PATCH 2/2] init: Fix -Wstringop-truncation warning on gcc 8.1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



gcc 8.1 on DragonFlyBSD is warning below.

The code looks correct, but gcc 8.1 seems to be complaining
on length argument "strlen(filename)".

Replacing the length with "len - ((ts - file) + 1) - 1",
(i.e. buffer_size - leading_directory_size_with_slash - 1)
can silence the warning, but this equals "strlen(filename)".
Neither allows copying beyond limit of "full_fn" whose size
is "len".

--
init.c:2042:6: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
      strncpy(full_fn + (ts - file) + 1,
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       filename, strlen(filename));
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@xxxxxxxxx>
---
 init.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/init.c b/init.c
index a2b70c4..682a0c2 100644
--- a/init.c
+++ b/init.c
@@ -2040,7 +2040,8 @@ static int __parse_jobs_ini(struct thread_data *td,
 					strncpy(full_fn,
 						file, (ts - file) + 1);
 					strncpy(full_fn + (ts - file) + 1,
-						filename, strlen(filename));
+						filename,
+						len - ((ts - file) + 1) - 1);
 					full_fn[len - 1] = 0;
 					filename = full_fn;
 				}
-- 
1.7.1




[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux