compilation warning on msys2

12 views
Skip to first unread message

Christian Brabandt

unread,
Oct 2, 2020, 8:41:27 AM10/2/20
to vim...@vim.org
Hi,
I see the following compiler warning, when compiling using msys2:

In file included from dict.c:14:
In function 'dictitem_copy',
inlined from 'dict_extend' at dict.c:1001:9:
vim.h:1583:26: warning: 'strcpy' offset 0 from the object at '<unknown>' is out of the bounds of referenced subobject 'di_key' with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0 [-Warray-bounds]
1583 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim.h:1583:26: note: in definition of macro 'STRCPY'
1583 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
| ^~~~~~
In file included from vim.h:1812,
from dict.c:14:
dict.c: In function 'dict_extend':
structs.h:1487:12: note: subobject 'di_key' declared here
1487 | char_u di_key[1]; // key (actually longer!)
| ^~~~~~

gcc --version
gcc (Rev3, Built by MSYS2 project) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Not sure what a fix would be, so no patch this time.

Best,
Christian
--
Ein Mann, der zum Ehemann paßt, den wollen die wenigsten Mädchen gern heiraten.
-- Moritz Goldschmidt

Bram Moolenaar

unread,
Oct 2, 2020, 12:13:03 PM10/2/20
to vim...@googlegroups.com, Christian Brabandt, vim...@vim.org

Christian wrote:

> I see the following compiler warning, when compiling using msys2:
>
> In file included from dict.c:14:
> In function 'dictitem_copy',
> inlined from 'dict_extend' at dict.c:1001:9:
> vim.h:1583:26: warning: 'strcpy' offset 0 from the object at '<unknown>' is out of the bounds of referenced subobject 'di_key' with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0 [-Warray-bounds]
> 1583 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> vim.h:1583:26: note: in definition of macro 'STRCPY'
> 1583 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
> | ^~~~~~
> In file included from vim.h:1812,
> from dict.c:14:
> dict.c: In function 'dict_extend':
> structs.h:1487:12: note: subobject 'di_key' declared here
> 1487 | char_u di_key[1]; // key (actually longer!)
> | ^~~~~~
>
> gcc --version
> gcc (Rev3, Built by MSYS2 project) 10.1.0
> Copyright (C) 2020 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> Not sure what a fix would be, so no patch this time.

We can use memmove() instead. The string length is already computed,
thus it could be a tiny bit faster as well.

--
If Pacman had affected us as kids we'd be running around in dark rooms,
munching pills and listening to repetitive music.
-- Marcus Brigstocke

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages