git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: mingw: use COPY_ARRAY for copying array

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 13, 2019, 08:55 UTC
Message-ID
<nycvar.QRO.7.76.6.1911130954470.46@tvgsbejvaqbjf.bet>
In-Reply-To
<35123410-245b-0e3f-7227-94c293b57182@web.de>
Hi René,
On Tue, 12 Nov 2019, René Scharfe wrote:
Show 11 quoted lines
> Use the macro COPY_ARRAY to copy array elements.  The result is shorter
> and safer, as it infers the element type automatically and does a (very)
> basic type compatibility check for its first two arguments.
>
> Coccinelle and contrib/coccinelle/array.cocci did not generate this
> conversion due to the offset of 1 at both source and destination and
> because the source is a const pointer; the semantic patch cautiously
> handles only pure pointers and array references of the same type.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---

Looks good to me. Thanks, Dscho

Show 20 quoted lines
>  compat/mingw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index fe609239dd..2f4654c968 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1566,7 +1566,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
>  		while (argv[argc]) argc++;
>  		ALLOC_ARRAY(argv2, argc + 1);
>  		argv2[0] = (char *)cmd;	/* full path to the script file */
> -		memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
> +		COPY_ARRAY(&argv2[1], &argv[1], argc);
>  		exec_id = trace2_exec(prog, argv2);
>  		pid = mingw_spawnv(prog, argv2, 1);
>  		if (pid >= 0) {
> --
> 2.24.0
>
>
Previous: René Scharfe
Message 2 of 2 in “mingw: use COPY_ARRAY for copying array”
  1. René ScharfeNov 12, 2019
  2. Johannes SchindelinNov 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.