{"thread":{"id":"52253","subject":"mingw: use COPY_ARRAY for copying array","startedAt":"2019-11-12T21:41:23Z","lastAt":"2019-11-13T08:55:23Z","messageCount":2,"participants":["René Scharfe","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"386048","messageId":"35123410-245b-0e3f-7227-94c293b57182@web.de","threadId":"52253","inReplyTo":null,"subject":"mingw: use COPY_ARRAY for copying array","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-12T21:41:14Z","receivedAt":"2019-11-12T21:41:23Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use the macro COPY_ARRAY to copy array elements.  The result is shorter\nand safer, as it infers the element type automatically and does a (very)\nbasic type compatibility check for its first two arguments.\n\nCoccinelle and contrib/coccinelle/array.cocci did not generate this\nconversion due to the offset of 1 at both source and destination and\nbecause the source is a const pointer; the semantic patch cautiously\nhandles only pure pointers and array references of the same type.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n compat/mingw.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex fe609239dd..2f4654c968 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1566,7 +1566,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)\n \t\twhile (argv[argc]) argc++;\n \t\tALLOC_ARRAY(argv2, argc + 1);\n \t\targv2[0] = (char *)cmd;\t/* full path to the script file */\n-\t\tmemcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);\n+\t\tCOPY_ARRAY(&argv2[1], &argv[1], argc);\n \t\texec_id = trace2_exec(prog, argv2);\n \t\tpid = mingw_spawnv(prog, argv2, 1);\n \t\tif (pid >= 0) {\n--\n2.24.0\n\n"},{"id":"386100","messageId":"nycvar.QRO.7.76.6.1911130954470.46@tvgsbejvaqbjf.bet","threadId":"52253","inReplyTo":"35123410-245b-0e3f-7227-94c293b57182@web.de","subject":"Re: mingw: use COPY_ARRAY for copying array","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-11-13T08:55:03Z","receivedAt":"2019-11-13T08:55:23Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi René,\n\nOn Tue, 12 Nov 2019, René Scharfe wrote:\n\n> Use the macro COPY_ARRAY to copy array elements.  The result is shorter\n> and safer, as it infers the element type automatically and does a (very)\n> basic type compatibility check for its first two arguments.\n>\n> Coccinelle and contrib/coccinelle/array.cocci did not generate this\n> conversion due to the offset of 1 at both source and destination and\n> because the source is a const pointer; the semantic patch cautiously\n> handles only pure pointers and array references of the same type.\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n\nLooks good to me. Thanks,\nDscho\n\n>  compat/mingw.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/compat/mingw.c b/compat/mingw.c\n> index fe609239dd..2f4654c968 100644\n> --- a/compat/mingw.c\n> +++ b/compat/mingw.c\n> @@ -1566,7 +1566,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)\n>  \t\twhile (argv[argc]) argc++;\n>  \t\tALLOC_ARRAY(argv2, argc + 1);\n>  \t\targv2[0] = (char *)cmd;\t/* full path to the script file */\n> -\t\tmemcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);\n> +\t\tCOPY_ARRAY(&argv2[1], &argv[1], argc);\n>  \t\texec_id = trace2_exec(prog, argv2);\n>  \t\tpid = mingw_spawnv(prog, argv2, 1);\n>  \t\tif (pid >= 0) {\n> --\n> 2.24.0\n>\n>\n"}]}