On 05-May-2019 05:09, Bram Moolenaar wrote:
Patch 8.1.1270
Problem: Cannot see current match position.
Solution: Show "3/44" when using the "n" command and "S" is not in
'shortmess'. (Christian Brabandt, closes #4317)
Files: runtime/doc/options.txt, runtime/doc/pattern.txt, src/option.c,
src/option.h, src/search.c, src/testdir/Make_all.mak,
src/testdir/test_search_stat.vim
After this patch, mingw64 (gcc 8.3.1) throws up these warnings:
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -pipe -march=native -Wall
-O3 -fomit-frame-pointer -freg-struct-return search.c -o objnative/search.o
In file included from search.c:13:
search.c: In function 'do_search':
vim.h:1568:29: warning: 'strncpy' output truncated before terminating
nul copying as many bytes from a string as its length
[-Wstringop-truncation]
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim.h:1568:29: note: in definition of macro 'STRNCPY'
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^~~~~~~
vim.h:1566:23: note: length computed here
#define STRLEN(s) strlen((char *)(s))
^
vim.h:1568:72: note: in definition of macro 'STRNCPY'
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^
search.c:1418:30: note: in expansion of macro 'STRLEN'
STRNCPY(msgbuf + 2, p, STRLEN(p));
^~~~~~
vim.h:1568:29: warning: 'strncpy' output truncated before terminating
nul copying as many bytes from a string as its length
[-Wstringop-truncation]
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim.h:1568:29: note: in definition of macro 'STRNCPY'
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^~~~~~~
vim.h:1566:23: note: length computed here
#define STRLEN(s) strlen((char *)(s))
^
vim.h:1568:72: note: in definition of macro 'STRNCPY'
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^
search.c:1421:30: note: in expansion of macro 'STRLEN'
STRNCPY(msgbuf + 1, p, STRLEN(p));
^~~~~~
In function 'search_stat',
inlined from 'do_search' at search.c:1584:6:
vim.h:1568:29: warning: 'strncpy' output truncated before terminating
nul copying as many bytes from a string as its length
[-Wstringop-truncation]
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim.h:1568:29: note: in definition of macro 'STRNCPY'
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^~~~~~~
search.c: In function 'do_search':
vim.h:1566:23: note: length computed here
#define STRLEN(s) strlen((char *)(s))
^
vim.h:1568:72: note: in definition of macro 'STRNCPY'
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s),
(size_t)(n))
^
search.c:5009:50: note: in expansion of macro 'STRLEN'
STRNCPY(msgbuf + STRLEN(msgbuf) - STRLEN(t), t, STRLEN(t));
^~~~~~
Please check the attached patch which tries to correct it.
Cheers
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
--- search.c.orig 2019-05-05 06:14:21.367356400 +1000
+++ search.c 2019-05-05 08:32:13.883849000 +1000
@@ -26,7 +26,7 @@
#ifdef FEAT_VIMINFO
static void wvsp_one(FILE *fp, int idx, char *s, int sc);
#endif
-static void search_stat(int dirc, pos_T *pos, char_u *msgbuf);
+static void search_stat(int dirc, pos_T *pos, char_u *msgbuf, size_t
msgbuf_size);
/*
* This file contains various searching-related routines. These fall into
@@ -1218,7 +1218,7 @@
char_u *strcopy = NULL;
char_u *ps;
char_u *msgbuf = NULL;
- size_t len;
+ size_t len = 0;
/*
* A line offset is not remembered, this is vi compatible.
@@ -1415,10 +1415,10 @@
{
// Use a space to draw the composing char on.
msgbuf[1] = ' ';
- STRNCPY(msgbuf + 2, p, STRLEN(p));
+ STRNCPY(msgbuf + 2, p, len - 2);
}
else
- STRNCPY(msgbuf + 1, p, STRLEN(p));
+ STRNCPY(msgbuf + 1, p, len - 1);
if (spats[0].off.line || spats[0].off.end || spats[0].off.off)
{
p = msgbuf + STRLEN(p) + 1;
@@ -1581,7 +1581,7 @@
&& c != FAIL
&& !shortmess(SHM_SEARCHCOUNT)
&& msgbuf != NULL)
- search_stat(dirc, &pos, msgbuf);
+ search_stat(dirc, &pos, msgbuf, len);
/*
* The search command can be followed by a ';' to do another search.
@@ -4911,7 +4911,8 @@
search_stat(
int dirc,
pos_T *pos,
- char_u *msgbuf)
+ char_u *msgbuf,
+ size_t msgbuf_size)
{
int save_ws = p_ws;
int wraparound = FALSE;
@@ -4981,6 +4982,7 @@
{
#define STAT_BUF_LEN 10
char t[STAT_BUF_LEN] = "";
+ size_t msgbuf_len = STRLEN(msgbuf);
#ifdef FEAT_RIGHTLEFT
if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
@@ -5006,7 +5008,9 @@
else
vim_snprintf(t, STAT_BUF_LEN, "[%d/%d]", cur, cnt);
}
- STRNCPY(msgbuf + STRLEN(msgbuf) - STRLEN(t), t, STRLEN(t));
+
+ // append the count
+ STRNCPY(msgbuf + msgbuf_len, t, msgbuf_size - msgbuf_len);
if (dirc == '?' && cur == 100)
cur = -1;