John Marriott wrote:
> After cleaning my vim source repo and rebuilding with the brand new gcc
> 10.1 (mingw64), I get these warnings:
> <snip>
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return main.c -o gobjnative/main.o
> In file included from main.c:11:
> main.c: In function 'early_arg_scan':
> vim.h:343:33: warning: 'I' flag used with '%x' gnu_scanf format [-Wformat=]
> 343 | # define SCANF_HEX_LONG_U "%Ix"
> | ^~~~~
[...]
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return dict.c -o gobjnative/dict.o
> In file included from dict.c:14:
> In function 'dictitem_copy',
> inlined from 'dict_extend' at dict.c:936:9:
> vim.h:1591: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]
> 1591 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> vim.h:1591:26: note: in definition of macro 'STRCPY'
> 1591 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
> | ^~~~~~
> In file included from vim.h:1815,
> from dict.c:14:
> dict.c: In function 'dict_extend':
> structs.h:1466:12: note: subobject 'di_key' declared here
> 1466 | char_u di_key[1]; // key (actually longer!)
> | ^~~~~~
This probably can't be avoided, the compiler doesn't see the "actually
longer" remark. Perhaps GCC has an annotation to suppress the warning?
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return evalvars.c -o gobjnative/evalvars.o
> evalvars.c: In function 'lookup_scriptvar':
> cc1.exe: warning: function may return address of local variable
> [-Wreturn-local-addr]
> evalvars.c:2504:12: note: declared here
> 2504 | char_u buffer[30];
> | ^~~~~~
I'll fix this one.
> gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
> -DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
> -DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
> -freg-struct-return userfunc.c -o gobjnative/userfunc.o
> In file included from userfunc.c:14:
> In function 'cat_func_name',
> inlined from 'get_user_func_name' at userfunc.c:3425:2:
> vim.h:1591:26: warning: 'strcpy' offset 0 from the object at '<unknown>'
> is out of the bounds of referenced subobject 'uf_name
> ' with type 'char_u[1]' {aka 'unsigned char[1]'} at offset 0
> [-Warray-bounds]
> 1591 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> vim.h:1591:26: note: in definition of macro 'STRCPY'
> 1591 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
> | ^~~~~~
> In file included from vim.h:1815,
> from userfunc.c:14:
> userfunc.c: In function 'get_user_func_name':
> structs.h:1569:12: note: subobject 'uf_name' declared here
> 1569 | char_u uf_name[1]; // name of function (actually longer); can
> | ^~~~~~~
> </snip>
Same reason, uf_name is used as the key in the function hashtable.
> I've had a look at the vim.h warning (the one from main.c). From what I
> can gather the "I" in the "%Ix" and "%Iu" scan format strings is a
> MS-specific thing. Anyhow, replacing the "I" with "z" in the format
> strings (lines 343 to 345 in vim.h) makes the warnings go away (see the
> attached patch).
This probably causes problems for other compilers, the format was like
this for a reason. Is there an #ifdef we can use for gcc?
--
Proof techniques #2: Proof by Oddity.
SAMPLE: To prove that horses have an infinite number of legs.
(1) Horses have an even number of legs.
(2) They have two legs in back and fore legs in front.
(3) This makes a total of six legs, which certainly is an odd number of
legs for a horse.
(4) But the only number that is both odd and even is infinity.
(5) Therefore, horses must have an infinite number of legs.
/// Bram Moolenaar -- [email protected] -- 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 ///
--
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202005091141.049Bfprm009634%40masaka.moolenaar.net.