From b7d8a41d91dcfebe9a5f3d0cf2f0bb0b8d59e32e Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Sat, 9 May 2026 02:47:00 +0800 Subject: [PATCH] build: strncat warning in buf_write #39684 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make gcc happy ``` src/nvim/bufwrite.c: In function ‘buf_write’: src/nvim/bufwrite.c:1674:5: warning: ‘strncat’ specified bound depends on the length of the source argument [-Wstringop-overflow=] 1674 | strncat(msg_id + 14, IObuff, strlen(IObuff) - 1); | ^ src/nvim/bufwrite.c:1674:34: note: length computed here 1674 | strncat(msg_id + 14, IObuff, strlen(IObuff) - 1); | ^ src/nvim/fileio.c: In function ‘filemess’: src/nvim/fileio.c:137:5: warning: ‘strncat’ specified bound depends on the length of the source argument [-Wstringop-overflow=] 137 | strncat(msg_id + 14, IObuff, strlen(IObuff) - 1); | ^ src/nvim/fileio.c:137:34: note: length computed here 137 | strncat(msg_id + 14, IObuff, strlen(IObuff) - 1); | ^ ``` --- src/nvim/bufwrite.c | 4 ++-- src/nvim/fileio.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index cf158bf545..efc30b71a0 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -1669,9 +1669,9 @@ restore_backup: #endif if (!filtering) { add_quoted_fname(IObuff, IOSIZE, buf, fname); - // Append the filename to the message ID. + // Append the filename (without trailing char) to the message ID. char msg_id[IOSIZE + 14] = "nvim.bufwrite "; - strncat(msg_id + 14, IObuff, strlen(IObuff) - 1); + xstrlcat(msg_id, IObuff, 14 + strlen(IObuff)); bool insert_space = false; if (write_info.bw_conv_error) { xstrlcat(IObuff, _(" CONVERSION ERROR"), IOSIZE); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 022509b933..3a679e6454 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -132,9 +132,9 @@ void filemess(buf_T *buf, char *name, char *s) msg_scrolled_ign = true; // may truncate the message to avoid a hit-return prompt if (*s == NUL) { - // Append the filename to the message ID. + // Append the filename (without trailing char) to the message ID. char msg_id[IOSIZE + 14] = "nvim.bufwrite "; - strncat(msg_id + 14, IObuff, strlen(IObuff) - 1); + xstrlcat(msg_id, IObuff, 14 + strlen(IObuff)); msg_progress(IObuff, msg_id, "running", 0, false, true); } else { msg_outtrans(msg_may_trunc(false, IObuff), 0, false);